﻿/*-----------*/
/* Ajax Root */
/*-----------*/
var GT5Ajax = Class.create();
GT5Ajax.prototype =
{
    initialize: function () { },
    complete: function (result) { },
    request_url: "",
    pars: "",
    sync: true,
    pars: "a",
    execute: function () {
        new Ajax.Request(
			this.request_url,
			{
			    method: 'post',
			    asynchronous: this.sync,
			    parameters: this.pars,

			    onComplete: function (request) {
			        var result = request.responseText;
			        this.complete(result);
			    } .bindAsEventListener(this, false),

			    onSuccess: function (request) {
			        var result = request.responseText;
			        this.success(result);
			    } .bindAsEventListener(this, false),

			    on400: function (request) {
			        var result = request.responseText;
			        this.on400(result);
			    } .bindAsEventListener(this, false),

			    on599: function (request) {
			        var result = request.responseText;
			        this.on599(result);
			    } .bindAsEventListener(this, false),

			    onFailure: function (request, json) {
			        alert("Network Failure");
			    }
			}
		);
    },
    on400: function (result) {
        popup.openNormalError();
    }
}

/*---------*/
/* PROFILE */
/*---------*/
var GT5Profile = Class.create();
Object.extend(GT5Profile.prototype, GT5Ajax.prototype);
Object.extend(GT5Profile.prototype,
{
    request_url: "",
    locale_url: "",
    online_id: "",

    driverlist_limit: 6,
    carlist_limit: 6,

    /* JOB */
    FRIEND_LIST: 0,
    MAIN_PROFILE: 1,
    UPDATE_AUTO_MESSAGE: 2,
    UPDATE_PROFILE: 3,
    GET_CARLIST: 4,
    GET_DRIVERLIST: 5,

    /* MODE */
    REMOTE_RACE: 0,
    PROFILE: 1,

    initialize: function (online_id, locale_url) {
        this.online_id = online_id;
        this.locale_url = locale_url;
        this.request_url = 'https://us.gran-turismo.com/' + locale_url + '/api/gt5/profile/';
    },

    on400: function (res) {
        alert("400 error");
    },

    complete: function (res) {
        var data = res.evalJSON();
        if (this.job == this.MAIN_PROFILE) {
            target_bbs_id = data.number;
            $('profile_online_id').innerHTML = data.id;
            $('profile_comment').innerHTML = data.comment;
        }
        else if (this.job == this.FRIEND_LIST) {
            this.updateFriendListProfile(data);
        }
        else if (this.job == this.UPDATE_PROFILE) {
            this.doneUpdateProfile(data);
        }
        else if (this.job == this.GET_DRIVERLIST) {
            //alert(res);
            if (this.mode == this.PROFILE)
                this.updateDriverListForProfileTab(data);
            else if (this.mode == this.REMOTE_RACE)
                this.updateDriverListForMatching(data);
        }
        else if (this.job == this.GET_CARLIST) {
            this.updateCarListForProfileTab(data);
        }
    },

    /* Remote Race DriverList */
    getDriverListForMatching: function () {
        this.job = this.GET_DRIVERLIST;
        this.mode = this.REMOTE_RACE;
        this.pars = $H({ job: this.job, online_id: this.online_id }).toQueryString();
        this.execute();
    },

    updateDriverListForMatching: function (data) {
        $('gt5bspec_matching_driver_list').innerHTML = this.getDriverListHtmlForMatching(data);
        driver_data_list = data;
        popup.popupHeightCorrection();
    },

    getDriverListHtmlForMatching: function (data) {
        var html = '';
        var is_entryed = false;
        for (i = 0; i < data.length; i++) {
            is_entryed = false;
            for (j = 0; j < entry_board.entry_board.length; j++) {
                if (entry_board.entry_board[j].driver_id == data[i].driver_id) {
                    is_entryed = true;
                    break;
                }
            }
            if (data[i].status == 1 && is_entryed == false) {
                html += '\
	<dl class="active">\
	<dd class="driver_select"><a href="javascript:void(0);" onclick="gt5bspec.driverSelector(<-NUMBER->,\'<-USER_ID->\')">&nbsp;</a></dd>\
				';
            }
            else {
                html += '\
	<dl>\
	<dd class="lock"><img src="/common/images/gt5/remote_race/entry/driver_list/lock.png" widtn="90" height="60" alt="lock" /></dd>\
				';
            }
            html += '\
	<dd class="helmet"><img src="/common/images/gt5/driver/<-HELMET->.png" height="60" alt="<-DRIVER_NAME->" /></dd>\
	<dd class="condition"><img src="/common/images/gt5/remote_race/entry/driver_list/condition<-CONDITION->.png" /></dd>\
	<dd class="driver_name"><-DRIVER_NAME-></dd>\
	<dd class="driver_credit_icon icon_<-CREDIT_ICON->">&nbsp;</dd>\
	<dd class="driver_class" style="background-image:url(/local/' + this.locale_url + '/images/gt5/remote_race/t_class.png);"><-DRIVER_CLASS-></dd>\
	<dd class="exp_bar_frame">&nbsp;</dd>\
	<dd class="exp_bar" style="width:<-BAR_WIDTH->px">&nbsp;</dd>\
	<dd class="selector" id="selector_<-NUMBER->"><img src="/common/images/gt5/remote_race/entry/driver_list/check.png" /></dd>\
	</dl>';

            html = html.replace(/<-NAME->/g, data[i].name);
            html = html.replace(/<-DRIVER_ID->/g, data[i].driver_id);
            html = html.replace(/<-NUMBER->/g, i);
            html = html.replace(/<-HELMET->/g, data[i].helmet_color);
            html = html.replace(/<-DRIVER_NAME->/g, data[i].name);
            html = html.replace(/<-CREDIT_ICON->/g, onlineCreditIconConverter(data[i].online_credit, this.locale_url));
            html = html.replace(/<-DRIVER_CLASS->/g, data[i].level);
            html = html.replace(/<-DRIVER_STATUS->/g, data[i].status);
            html = html.replace(/<-USER_ID->/g, data[i].user_id);
            html = html.replace(/<-CONDITION->/g, convertCondition(data[i].condition));
            html = html.replace(/<-BAR_WIDTH->/g, Math.floor(144 * (data[i].experimental / (data[i].expnextlevel / 100) / 100)));
        }
        for (j = i; j < 6; j++) {
            html += '<dl><dd>&nbsp;</dd></dl>';
        }
        return html;
    },

    /* MyHome Profile DriverList */
    getDriverListForProfileTab: function () {
        this.job = this.GET_DRIVERLIST;
        this.mode = this.PROFILE;
        this.pars = $H({ job: this.job, online_id: this.online_id }).toQueryString();
        this.execute();
    },
    updateDriverListForProfileTab: function (data) {
        var html = "";
        var driverlist_qty = data.length;

        if (driverlist_qty > this.driverlist_limit)
            driverlist_qty = this.driverlist_limit;

        driver_datalist_popup = new Array(data.length);

        html += '<dt>' + localize_profile_driverlist + '</dt>'
        for (i = 0; i < data.length; i++) {
            html += '\
	<dd class="no_blank" title="<-DRIVER_NAME->">\
		<a href="javascript:void(0);" onclick="popup.openDriverProfile(<-DATA_INDEX->);">\
			<img src="/common/images/gt5/driver/<-HELMET->.png" width="160" height="90" alt="<-DRIVER_NAME->" />\
			<span class="driver_online_credit icon<-CREDIT_ICON->">&nbsp;</span>\
			<span class="driver_class_header"><img src="/local/' + this.locale_url + '/images/gt5/header/t_class.png" height="28" alt="' + localize_dirver_class + '" /></span>\
			<span class="driver_class"><-DRIVER_CLASS-></span>\
		</a>\
	</dd>\
			';
            html = html.replace(/<-DATA_INDEX->/g, i);
            html = html.replace(/<-HELMET->/g, data[i].helmet_color);
            html = html.replace(/<-DRIVER_NAME->/g, data[i].name);
            html = html.replace(/<-DRIVER_CLASS->/g, data[i].level);
            html = html.replace(/<-CREDIT_ICON->/g, onlineCreditIconConverter(data[i].online_credit, this.locale_url));

            driver_datalist_popup[i] = data[i];
        }
        for (; i < this.driverlist_limit; i++) {
            html += '<dd>&nbsp;</dd>';
        }
        $('gt5_profile_driver_list').innerHTML = html;
    },

    /* MyHome CarList */
    getCarListForProfileTab: function () {
        this.job = this.GET_CARLIST;
        this.pars = $H({ job: this.job, online_id: this.online_id }).toQueryString();
        this.execute();
    },
    updateCarListForProfileTab: function (data) {
        var html = "";
        var carlist_qty = data.length;

        if (carlist_qty > this.carlist_limit)
            carlist_qty = this.carlist_limit;

        html += '<dt>' + localize_profile_garage + '</dt>'
        for (i = 0; i < carlist_qty; i++) {
            html += '<dd class="no_blank"><img src="<-BASE_URL-><-PHOTO_ID->_0.png" title="<-CARNAME->" width="168"></dd>';

            html = html.replace(/<-BASE_URL->/g, photo_base_url);
            html = html.replace(/<-PHOTO_ID->/g, data[i].thumbnail_photo_id);
            html = html.replace(/<-CARNAME->/g, data[i].car_name);
        }
        for (; i < this.carlist_limit; i++) {
            html += '<dd>&nbsp;</dd>';
        }
        $('gt5_profile_garage_list').innerHTML = html;
    },

    setProfile: function () {
        if (target_profile.photo_avatar != "")
            $('gt5_profile_image').innerHTML = '<a href="javascript:void(0);" onclick="popup.openProfile(\'' + target_profile.id + '\')"><img src="' + photo_base_url + target_profile.photo_avatar + '_0.jpg" width="152" height="152" /></a>';
        else
            $('gt5_profile_image').innerHTML = '<a href="javascript:void(0);" style="display:block; margin:2px 0 0 4px;width:152px; height:152px;" onclick="popup.openProfile(\'' + target_profile.id + '\')">&nbsp;</a>';

        //<span class="flag '+target_profile.country+'">&nbsp;</span>
        $('profile_online_id').innerHTML = '<p>' + target_profile.id + '</p>';
        $('profile_comment').innerHTML = target_profile.comment.replace(/\s/g, '&nbsp;');
        $('profile_playtime').innerHTML = target_profile.playtime.replace(/\s/g, '&nbsp;');
        $('profile_friend_count').innerHTML = target_profile.friend_count;
        $('gt5_center_header').id = "gt5_center_header_" + target_profile.menu_matiere;
        $('contents_left_gt5').className = "contents_left_gt5 color_" + target_profile.menu_color;
        $('gt5_view_select').className = "gt5_view_select color_" + target_profile.menu_color
        if ($('profile_welcomemessage'))
            $('profile_welcomemessage').innerHTML = target_profile.welcomemessage;
    },
    getMainProfile: function () {
        this.job = this.MAIN_PROFILE;
        this.pars = $H({ online_id: this.online_id }).toQueryString();
        this.sync = false;
        this.execute();
    },

    getFriendListProfile: function (index) {
        this.index = index;
        this.job = this.FRIEND_LIST;
        this.pars = $H({ online_id: this.online_id }).toQueryString();
        this.execute();
    },
    updateFriendListProfile: function (data) {
        if (data.photo_avatar != "") {
            $("friendlist_image_" + this.online_id).innerHTML = '<img src="' + photo_base_url + data.photo_avatar + '_0.jpg" width="48" height="48" />';
        }
        $('friendlist_level_' + this.online_id).innerHTML = '<img src="/common/images/gt5/friend_list/a_icon.gif" width="15" height="9" alt="" />&nbsp;' + localize_profile_lv + '&nbsp;' + data.aspec_level + '&nbsp;&nbsp;&nbsp;<img src="/common/images/gt5/friend_list/b_icon.gif" width="15" height="9" alt="" />&nbsp;' + localize_profile_lv + '&nbsp;' + data.bspec_level;

        friend_data_list[this.index] = data;

        $('image_bg_' + this.online_id).className = "image_bg color_" + data.menu_color;

        if (friend_list_size == friend_data_list.compact().length) {
            $('friendlist_loading').style.display = "none";
            if (url_hash[1] == "aspec") {
                $('friendlist_psnid').className = "off";
                $('friendlist_aspec').className = "on";
                $('friendlist_bspec').className = "off";
                updateAnchor();
            }
            else if (url_hash[1] == "bspec") {
                $('friendlist_psnid').className = "off";
                $('friendlist_aspec').className = "off";
                $('friendlist_bspec').className = "on";
                updateAnchor();
            }
            else {
                $('friendlist_psnid').className = "on";
                $('friendlist_aspec').className = "off";
                $('friendlist_bspec').className = "off";
                updateAnchor();
            }
        }
    },

    postProfile: function () {
        $('update_profile_button').style.display = "inline";
        $('cancel_profile_button').style.display = "inline";
        this.job = this.UPDATE_PROFILE;

        for (var i = 0; i < document.profile_form.playtime_level.length; i++) {
            if (document.profile_form.playtime_level[i].checked == true)
                var playtime_level = document.profile_form.playtime_level[i].value;
        }
        for (var i = 0; i < document.profile_form.comment_level.length; i++) {
            if (document.profile_form.comment_level[i].checked == true)
                var comment_level = document.profile_form.comment_level[i].value;
        }
        for (var i = 0; i < document.profile_form.profile_button_level.length; i++) {
            if (document.profile_form.profile_button_level[i].checked == true)
                var profile_button_level = document.profile_form.profile_button_level[i].value;
        }

        this.pars = $H({ job: this.job, playtime_level: playtime_level, playtime: $('myhome_setting_playtime').value.replace(/[\n\r]/g, ''), comment_level: comment_level, comment: $('myhome_setting_comment').value.replace(/[\n\r]/g, ''), profile_level: profile_button_level, welcomemessage: $('myhome_setting_welcomemessage').value }).toQueryString();
        //alert(this.pars);

        this.execute();
    },

    doneUpdateProfile: function (data) {
        $('profile_playtime').innerHTML = data.playtime;
        $('profile_comment').innerHTML = data.comment;
        popup.closePopup();
    },

    postAutoMessage: function () {
        alert("æœªå®Ÿè£…");
    }
});

/*-------------*/
/* FRIEND LIST */
/*-------------*/
var GT5FriendList = Class.create();
Object.extend(GT5FriendList.prototype, GT5Ajax.prototype);
Object.extend(GT5FriendList.prototype,
{
    request_url: "",
    locale_url: "",

    initialize: function (locale_url) {
        this.locale_url = locale_url;
        this.request_url = '/' + locale_url + '/api/gt5/profile/';
    },
    getFriendList: function () {
        $('gt5_friend_list_area').innerHTML = this.getFriendListHtml();
        fleXenv.fleXcrollMain("gt5_friend_list_area");
        if (friend_list_current >= (friend_id_list.length - 5))
            $('gt5_friend_list_area').fleXcroll.setScrollPos(false, $('gt5_friend_list_area').fleXdata.scrollPosition[1][1]);
        else if (friend_list_current >= 3)
            $('gt5_friend_list_area').fleXcroll.setScrollPos(false, (friend_list_current - 2) * 72);
        this.getFriendData();
    },

    getFriendData: function () {
        var friend_list = new Array(friend_id_list.length);
        for (i = 0; i < friend_id_list.length; i++) {
            friend_list[i] = new GT5Profile(friend_id_list[i], this.locale_url);
            friend_list[i].getFriendListProfile(i);
        }
    },
    getFriendListHtml: function () {
        var html = '';
        var friend_id_name = '';
        for (i = 0; i < friend_id_list.length; i++) {
            html += '\
				<dl class="gt5_friend_data<-FIRST_DATA->" id="<-FRIEND_ID->" name="<-FRIEND_ID->">\
					<dd class="image_bg" id="image_bg_<-FRIEND_ID->">&nbsp;</dd>\
					<dd class="image<-IS_ACTIVE->"><a href="/' + this.locale_url + '/gt5/user/<-FRIEND_ID->/<-URL_HASH->" id="friendlist_image_<-FRIEND_ID->">&nbsp;</a></dd>\
					<dt>' + (i + 1) + '. <-FRIEND_ID_NAME-></dt>\
					<dd class="level" id="friendlist_level_<-FRIEND_ID->">&nbsp;</dd>\
					<dd class="link"><a href="/' + this.locale_url + '/gt5/user/<-FRIEND_ID->/<-URL_HASH->">&nbsp;</a></dd>\
				</dl>\
			';
            if (i == 0)
                html = html.replace(/<-FIRST_DATA->/g, ' first_data');
            else
                html = html.replace(/<-FIRST_DATA->/g, '');

            html = html.replace(/<-FRIEND_ID->/g, friend_id_list[i]);

            if (friend_id_list[i].length > 9)
                friend_id_name = friend_id_list[i].substring(0, 8) + '...';
            else
                friend_id_name = friend_id_list[i];
            html = html.replace(/<-FRIEND_ID_NAME->/g, friend_id_name);

            if (target_profile.id == friend_id_list[i]) {
                friend_list_current = i;
                html = html.replace(/<-IS_ACTIVE->/g, ' active');
            }
            else {
                html = html.replace(/<-IS_ACTIVE->/g, '');
            }
            var friend_list_hash = '';
            var page_mode_hash = '';

            if (url_hash[0])
                page_mode_hash = url_hash[0];
            if (url_hash[1])
                friend_list_hash = ',' + url_hash[1];

            html = html.replace(/<-URL_HASH->/g, '#' + page_mode_hash + friend_list_hash);
        }
        return html;
    },
    getFriendListForBspec: function () {
        $('gt5_friend_list_area').innerHTML = this.getFriendListHtmlForBspec();
        fleXenv.fleXcrollMain("remoterace_friend_list");
    },

    getFriendListHtmlForBspec: function () {
        var html = '';
        html += '<div id="remoterace_friend_list" style="height:628px; overflow-y:auto; overflow-x:hidden;">';
        var online_driver_checker = new Array(friend_data_list.length);
        for (i = 0; i < friend_data_list.length; i++) {
            html += '\
				<div class="friend_list_wrapper">\
				<dl class="gt5_friend_data" id="<-FRIEND_ID->">\
					<dd class="image_bg color_<-MENU_COLOR->" id="image_bg_<-FRIEND_ID->">&nbsp;</dd>\
					<dd class="image"><a href="javascript:void(0);" onclick="popup.openBspecMatching(\'<-FRIEND_ID->\',\'<-LOCALE_URL->\');" id="friendlist_image_<-FRIEND_ID->"><img src="<-BASE_URL-><-PHOTO_AVATAR->_0.jpg" width="48" height="48" /></a></dd>\
					<dt><-FRIEND_ID-></dt>\
					<dd class="level" id="friendlist_level_<-FRIEND_ID->"><img src="/common/images/gt5/friend_list/a_icon.png" width="15" height="9" alt="" />&nbsp;<span><-LOCALIZE_LV-></span>&nbsp;<-A_LEVEL->&nbsp;&nbsp;&nbsp;&nbsp;<img src="/common/images/gt5/friend_list/b_icon.png" width="15" height="9" alt="" />&nbsp;<span><-LOCALIZE_LV-></span>&nbsp;<-B_LEVEL-></dd>\
					<dd class="grayout" id="friend_list_id_<-FRIEND_ID->">&nbsp;</dd>\
					<dd class="link"><a id="remote_friend_list_link_<-FRIEND_ID->" href="javascript:void(0);" onclick="popup.openBspecMatching(\'<-FRIEND_ID->\',\'<-LOCALE_URL->\');">&nbsp;</a></dd>\
				</dl>\
				</div>\
			';
            //'<img src="/common/images/gt5/friend_list/a_icon.gif" width="15" height="9" alt="" />&nbsp;'+localize_profile_lv+'&nbsp;' + data.aspec_level + '&nbsp;&nbsp;&nbsp;<img src="/common/images/gt5/friend_list/b_icon.gif" width="15" height="9" alt="" />&nbsp;'+localize_profile_lv+'&nbsp;' + data.bspec_level;

            html = html.replace(/<-FRIEND_ID->/g, friend_data_list[i].id);
            html = html.replace(/<-A_LEVEL->/g, friend_data_list[i].aspec_level);
            html = html.replace(/<-B_LEVEL->/g, friend_data_list[i].bspec_level);
            html = html.replace(/<-LOCALE_URL->/g, this.locale_url);
            html = html.replace(/<-BASE_URL->/g, photo_base_url);
            html = html.replace(/<-PHOTO_AVATAR->/g, friend_data_list[i].photo_avatar);
            html = html.replace(/<-MENU_COLOR->/g, friend_data_list[i].menu_color);

            html = html.replace(/<-LOCALIZE_LV->/g, localize_profile_lv);

            check_counter = 0;
            online_driver_checker[i] = new GT5Bspec(this.locale_url);
            online_driver_checker[i].checkOnlineDriver(friend_data_list[i].id);
        }
        html += '</div>';
        return html;
    },

    sortFriendList: function (key) {
        friend_data_list.sort(function (a, b) { return (a.id.toLowerCase() > b.id.toLowerCase()) ? 1 : -1; });

        for (i = 0; i < friend_data_list.length; i++) {
            if (friend_data_list[i].id == online_id) {
                var temp = friend_data_list[i];
                friend_data_list.splice(i, 1);
                friend_data_list.unshift(temp);
            }
        }

        if (key == "aspec") {
            friend_data_list.sort(function (a, b) { return b.aspec_level - a.aspec_level; });
        }
        else if (key == "bspec") {
            friend_data_list.sort(function (a, b) { return b.bspec_level - a.bspec_level; });
        }
        else if (key == "psnid") {
        }
    },

    compare_test: function (a, b) { alert("test"); },

    sortMyHomeFriendList: function (key) {
        this.sortFriendList(key);

        $('gt5_friend_list_area_contentwrapper').innerHTML = this.getFriendListHtmlForSort();

        if (friend_list_current >= (friend_data_list.length - 5))
            $('gt5_friend_list_area').fleXcroll.setScrollPos(false, $('gt5_friend_list_area').fleXdata.scrollPosition[1][1]);
        else if (friend_list_current >= 3)
            $('gt5_friend_list_area').fleXcroll.setScrollPos(false, (friend_list_current - 2) * 72);
        else
            $('gt5_friend_list_area').fleXcroll.setScrollPos(false, 0);
    },

    getFriendListHtmlForSort: function () {
        var html = '';
        for (i = 0; i < friend_data_list.length; i++) {
            html += '\
				<dl class="gt5_friend_data<-FIRST_DATA->" id="<-FRIEND_ID->">\
					<dd class="image_bg color_<-IMAGE_BG->" id="image_bg_<-FRIEND_ID->">&nbsp;</dd>\
					<dd class="image<-IS_ACTIVE->"><a href="/' + this.locale_url + '/gt5/user/<-FRIEND_ID->/<-URL_HASH->" id="friendlist_image_<-FRIEND_ID->"><-THUMBNAIL-><-MY_ICON-></a></dd>\
					<dt>' + (i + 1) + '. <-FRIEND_ID_NAME-></dt>\
					<dd class="level" id="friendlist_level_<-FRIEND_ID->"><img src="/common/images/gt5/friend_list/a_icon.gif" width="15" height="9" alt="" />&nbsp;<span>' + localize_profile_lv + '</span>&nbsp;<-ASPEC_LEVEL->&nbsp;&nbsp;&nbsp;&nbsp;<img src="/common/images/gt5/friend_list/b_icon.gif" width="15" height="9" alt="" />&nbsp;<span>' + localize_profile_lv + '</span>&nbsp;<-BSPEC_LEVEL-></dd>\
					<dd class="link"><a href="/' + this.locale_url + '/gt5/user/<-FRIEND_ID->/<-URL_HASH->">&nbsp;</a></dd>\
				</dl>\
			';
            if (i == 0)
                html = html.replace(/<-FIRST_DATA->/g, ' first_data');
            else
                html = html.replace(/<-FIRST_DATA->/g, '');

            html = html.replace(/<-FRIEND_ID->/g, friend_data_list[i].id);
            html = html.replace(/<-IMAGE_BG->/g, friend_data_list[i].menu_color);
            if (friend_data_list[i].id.length > 9)
                friend_id_name = friend_data_list[i].id.substring(0, 8) + '...';
            else
                friend_id_name = friend_data_list[i].id;
            html = html.replace(/<-FRIEND_ID_NAME->/g, friend_id_name);

            html = html.replace(/<-ASPEC_LEVEL->/g, friend_data_list[i].aspec_level);
            html = html.replace(/<-BSPEC_LEVEL->/g, friend_data_list[i].bspec_level);

            if (target_profile.id == friend_data_list[i].id) {
                friend_list_current = i;
                html = html.replace(/<-IS_ACTIVE->/g, ' active');
            }
            else {
                html = html.replace(/<-IS_ACTIVE->/g, '');
            }

            if (online_id == friend_data_list[i].id)
                html = html.replace(/<-MY_ICON->/g, '<img class="my_icon" src="/common/images/gt5/friend_list/my_icon.png" width="26" height="26" alt="" />');
            else
                html = html.replace(/<-MY_ICON->/g, '');

            var friend_list_hash = '';
            var page_mode_hash = '';

            if (url_hash[0])
                page_mode_hash = url_hash[0];
            if (url_hash[1])
                friend_list_hash = ',' + url_hash[1];

            html = html.replace(/<-URL_HASH->/g, '#' + page_mode_hash + friend_list_hash);

            if (friend_data_list[i].photo_avatar != "")
                html = html.replace(/<-THUMBNAIL->/g, '<img src="' + photo_base_url + friend_data_list[i].photo_avatar + '_0.jpg" width="48" height="48" />');
            else
                html = html.replace(/<-THUMBNAIL->/g, '');
        }
        return html;
    }
});

/*---------------*/
/* Event Ranking */
/*---------------*/
var GT5EventRanking = Class.create();
Object.extend(GT5EventRanking.prototype, GT5Ajax.prototype);
Object.extend(GT5EventRanking.prototype,
{
    request_url: "",
    locle_url: "",
    online_id: "",
    board_id: 0,
    ranking_detail_data: new Array(),

    GET_RANKING: 1,
    GET_MYRECORD: 2,

    initialize: function (online_id, board_id, locale_url) {
        this.request_url = '/' + locale_url + '/api/gt5/ranking/';
        this.locale_url = locale_url;
        this.online_id = online_id;
        //		this.board_id = board_id;
        this.board_id = "vnrP9LjF7tA=";
        this.getRankingBoard(1, 250);
    },

    on400: function (res) {
        alert("400 error : " + res);
    },

    success: function (res) {
        if (this.job == this.GET_RANKING)
            this.updateRankingBoard(res.evalJSON());
        else if (this.job == this.GET_MYRECORD)
            this.updateMyRecord(res.evalJSON());
    },

    getRankingBoard: function (start_rank, end_rank) {
        $('ranking_loading').style.display = 'block';
        this.job = this.GET_RANKING;
        this.pars = $H({ job: this.job, board_id: this.board_id, begin_rank: start_rank, end_rank: end_rank }).toQueryString();
        this.execute();
    },

    updateRankingBoard: function (data) {
        var list_html = "";
        var html = "";
        var create_time;

        list_html = this.getTableHeaderHtml();
        list_html += this.makeRankingTable(data);

        list_html = list_html.replace(/<-LOCALE_URL->/g, this.locale_url);
        Element.update($('academy_ranking_table'), list_html);
        $('ranking_loading').style.height = $('academy_ranking_table').offsetHeight + 'px';
        $('ranking_loading').style.display = 'none';

        if (this.online_id != "")
            this.getMyRecord();
    },

    getTableHeaderHtml: function () {
        return '\
<tr class="header">\
	<th class="rank"><div><p class="ranking_loading" id="ranking_loading"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></p><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_rank.png" class="iepngfix" height="20" width="74" alt="Rank" /></div></th>\
	<th class="onlineid"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_id.png" class="iepngfix" height="20" width="133" alt="Online ID" /></div>\</th>\
	<th class="time"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_time.png" class="iepngfix" height="20" width="45" alt="Time" /></div></th>\
	<th class="update"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_update.png" class="iepngfix" height="20" width="84" alt="Update" /></div></th>\
</tr>\
<tr id="myrecord">\
	<td class="self rank">- - -</td>\
	<td class="bg02 onlineid"><div id="caption">My Record</div></td>\
	<td class="bg01">- - -</td>\
	<td class="bg02">- - -</td>\
</tr>\
		'.replace(/<-LOCALE_URL->/g, this.locale_url);
    },

    makeRankingTable: function (data) {
        var list_html = '';
        var html = '';

        for (var i = 0; i < data.root.length; i++) {
            html = '\
	<tr>\
		<td class="bg01 rank"><span><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" /><-ONLINE_ID-></a></span></td>\
		<td class="bg01"><span><-SCORE-></span></td>\
		<td class="bg02"><span><-UPDATE_TIME-></span></td>\
	</tr>\
			';
            html = html.replace(/<-INDEX->/g, i + 1);
            html = html.replace(/<-RANK->/g, data.root[i].rank);
            html = html.replace(/<-ONLINE_ID->/g, data.root[i].online_id);
            html = html.replace(/<-COUNTRY->/g, data.root[i].country);
            html = html.replace(/<-SCORE->/g, data.root[i].score);
            html = html.replace(/<-UPDATE_TIME->/g, data.root[i].local_time);
            list_html += html;

            this.ranking_detail_data[i + 1] = {
                online_id: data.root[i].online_id,
                country: data.root[i].country,
                local_time: data.root[i].local_time,
                car_name: data.root[i].car_name,
                transmission: data.root[i].transmission,
                front_tire: data.root[i].front_tire,
                rear_tire: data.root[i].rear_tire,
                tcs: data.root[i].tcs,
                professional: data.root[i].professional,
                active_steering: data.root[i].active_steering,
                asm: data.root[i].asm,
                abs: data.root[i].abs,
                controller_type: data.root[i].controller_type
            };
        }
        return list_html;
    },

    getMyRecord: function () {
        var board_id = this.ranking_board[this.academy_round][$('academy_round').value][$('academy_area').value];
        this.job = this.GET_MYRECORD;
        this.pars = $H({ job: this.job, board_id: board_id }).toQueryString();
        this.execute();
    },

    updateMyRecord: function (data) {
        if (this.board_type == 0)
            Element.update($('myrecord'), this.makeMyRecordHtmlTotal(data));
        else
            Element.update($('myrecord'), this.makeMyRecordHtml(data));
    },

    makeMyRecordHtml: function (data) {
        var html = '\
		<td class="self rank"><span style="color:#000;"><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" />My Record</a></span></td>\
		<td class="bg01"><span><-SCORE-></span></td>\
		<td class="bg02"><span><-UPDATE_TIME-></span></td>\
		';
        html = html.replace(/<-INDEX->/g, 0);
        html = html.replace(/<-RANK->/g, data.root[0].rank);
        html = html.replace(/<-COUNTRY->/g, data.root[0].country);
        html = html.replace(/<-SCORE->/g, data.root[0].score);
        html = html.replace(/<-UPDATE_TIME->/g, data.root[0].local_time);
        this.ranking_detail_data[0] = {
            online_id: data.root[0].online_id,
            country: data.root[0].country,
            local_time: data.root[0].local_time,
            car_name: data.root[0].car_name,
            transmission: data.root[0].transmission,
            front_tire: data.root[0].front_tire,
            rear_tire: data.root[0].rear_tire,
            tcs: data.root[0].tcs,
            professional: data.root[0].professional,
            active_steering: data.root[0].active_steering,
            asm: data.root[0].asm,
            abs: data.root[0].abs,
            controller_type: data.root[0].controller_type
        };
        return html;
    }
});

/*----------------*/
/* AcademyRanking */
/*----------------*/
var GT5Ranking = Class.create();
Object.extend(GT5Ranking.prototype, GT5Ajax.prototype);
Object.extend(GT5Ranking.prototype,
{
    request_url: "",
    locle_url: "",
    online_id: "",
    academy_round: 0,
    board_type: 0,
    ranking_board: new Array(),
    ranking_detail_data: new Array(),
    result_json_name: "",

    GET_RANKING: 1,
    GET_MYRECORD: 2,

    ImageViewer: Class.create(),

    initialize: function (academy_round, locale_url, online_id, is_end) {
        if (is_end == 1) {
            this.locale_url = locale_url;
            this.getRankingBoard2();
        }
        else {
            this.request_url = '/' + locale_url + '/api/gt5/ranking/';
            this.academy_round = academy_round;
            this.locale_url = locale_url;
            this.online_id = online_id;
            this.ranking_board = [
				[
					["vnrP9LjF7tA=", "4M8H96LY37U=", "08ahXOg1Udg=", "IR4qjfFUxhE=", "KPL+24WvXDo="],
					["5ioMPZLlH4U=", "udpFCbtNxKM=", "m528dwQ0cfg=", "O13NfGJYidY=", "27l4jCnzAsU="],
					["mF/YWO7t3TM=", "WqXSAIbMQAw=", "1w7G7pMJabc=", "MVXQIw+IlHI=", "y98iN0AgcR0="],
					["GjcXgFC5g4A=", "arwxgv/xuw8=", "brt+CVuH0g4=", "SznY/c9/tRQ=", "6AWOSAAdbso="]
				],
				[
					["/vRRhheNocI=", "bp/SwFf9V1c=", "6Xfl0DBD3Fc=", "L6DXETpQGCw=", "LV0JSiathSE="],
					["7+BwqWx5QWk=", "ayPd9Oq9UbQ=", "GzD8pkD2wfQ=", "Quiwu4WOLrY=", "kKlqMYhwF9c="],
					["RhLSoXRNSlU=", "ae9CwAg9KQo=", "KpgHDgD6yqA=", "n577foiYeq8=", "hKfdtgrAcOs="]
				],
				[
					["q+PnXJnPsb8=", "L0SUT2NSQHQ=", "+DLbGiKbjLs=", "eJt/u6FEX2Q=", "qoe8XXGtAMA="],
					["FgrN4fBHqIY=", "4d65yobD1VM=", "c4u2cTNay+s=", "iSlJBLI3lq4=", "T4B2lIgbM5Q="],
					["cpvXPYvEIKY=", "Q6+bzalyBZw=", "R7jdXJx26Vk=", "0oB4qW/T3uo=", "FZ8HKEOzPm4="]
				]
			];
            this.getRankingBoard(1, 250);
        }
    },

    on400: function () {
        //		alert("400 error");
    },

    success: function (res) {
        if (this.job == this.GET_RANKING)
            this.updateRankingBoard(res.evalJSON());
        else if (this.job == this.GET_MYRECORD)
            this.updateMyRecord(res.evalJSON());
    },

    getMyRecord: function () {
        var board_id = this.ranking_board[this.academy_round][$('academy_round').value][$('academy_area').value];
        this.job = this.GET_MYRECORD;
        this.pars = $H({ job: this.job, board_id: board_id }).toQueryString();
        this.execute();
    },

    updateMyRecord: function (data) {
        if (this.board_type == 0)
            Element.update($('myrecord'), this.makeMyRecordHtmlTotal(data));
        else
            Element.update($('myrecord'), this.makeMyRecordHtml(data));
    },

    makeMyRecordHtml: function (data) {
        var html = '\
		<td class="self rank"><span style="color:#000;"><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" />My Record</a></span></td>\
		<td class="bg01"><span><-SCORE-></span></td>\
		<td class="bg02"><span><-UPDATE_TIME-></span></td>\
		';
        html = html.replace(/<-INDEX->/g, 0);
        html = html.replace(/<-RANK->/g, data.root[0].rank);
        html = html.replace(/<-COUNTRY->/g, data.root[0].country);
        html = html.replace(/<-SCORE->/g, data.root[0].score);
        html = html.replace(/<-UPDATE_TIME->/g, data.root[0].local_time);
        this.ranking_detail_data[0] = {
            online_id: data.root[0].online_id,
            country: data.root[0].country,
            local_time: data.root[0].local_time,
            car_name: data.root[0].car_name,
            transmission: data.root[0].transmission,
            front_tire: data.root[0].front_tire,
            rear_tire: data.root[0].rear_tire,
            tcs: data.root[0].tcs,
            professional: data.root[0].professional,
            active_steering: data.root[0].active_steering,
            asm: data.root[0].asm,
            abs: data.root[0].abs,
            controller_type: data.root[0].controller_type
        };
        return html;
    },

    makeMyRecordHtmlTotal: function (data) {
        html = '\
		<td class="self rank"><span style="color:#000;"><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" />My Record</a></span></td>\
		<td class="bg01"><span><-SCORE1-></span></td>\
		<td class="bg01"><span><-SCORE2-></span></td>\
		<td class="bg01"><span><-SCORE3-></span></td>\
		<td class="bg02"><span><-SCORE-></span></td>\
		';
        html = html.replace(/<-INDEX->/g, 0);
        html = html.replace(/<-RANK->/g, data.root[0].rank);
        html = html.replace(/<-COUNTRY->/g, data.root[0].country);
        html = html.replace(/<-SCORE1->/g, data.root[0].score_list[0]);
        html = html.replace(/<-SCORE2->/g, data.root[0].score_list[1]);
        html = html.replace(/<-SCORE3->/g, data.root[0].score_list[2]);
        html = html.replace(/<-SCORE->/g, data.root[0].score);

        this.ranking_detail_data[0] = {
            online_id: data.root[0].online_id,
            country: data.root[0].country,
            local_time: data.root[0].local_time,
            car_name: data.root[0].car_name,
            transmission: data.root[0].transmission,
            front_tire: data.root[0].front_tire,
            rear_tire: data.root[0].rear_tire,
            tcs: data.root[0].tcs,
            professional: data.root[0].professional,
            active_steering: data.root[0].active_steering,
            asm: data.root[0].asm,
            abs: data.root[0].abs,
            controller_type: data.root[0].controller_type
        };
        return html;
    },

    getRankingBoard: function (start_rank, end_rank) {
        $('ranking_loading').style.display = 'block';
        var board_id = this.ranking_board[this.academy_round][$('academy_round').value][$('academy_area').value];
        this.job = this.GET_RANKING;
        this.board_type = $('academy_round').value;
        this.pars = $H({ job: this.job, board_id: board_id, begin_rank: start_rank, end_rank: end_rank }).toQueryString();
        this.execute();
    },

    getRankingBoard2: function () {
        this.job = this.GET_RANKING;
        this.request_url = '/local/' + this.locale_url + '/data1/academy2011/';
        this.result_json_name = $('academy_area').value;
        this.request_url += this.result_json_name + '.json';
        this.execute();
    },

    updateRankingBoard: function (data) {
        var list_html = "";
        var html = "";
        var create_time;
        if (this.board_type == 0) {
            list_html = this.getTableHeaderHtmlTotal();
            list_html += this.makeRankingTableTotal(data);
        }
        else {
            list_html = this.getTableHeaderHtml();
            list_html += this.makeRankingTable(data);
        }

        list_html = list_html.replace(/<-LOCALE_URL->/g, this.locale_url);
        //		$('academy_ranking_table').innerHTML = list_html;
        Element.update($('academy_ranking_table'), list_html);
        $('ranking_loading').style.height = $('academy_ranking_table').offsetHeight + 'px';
        $('ranking_loading').style.display = 'none';

        if (this.online_id != "")
            this.getMyRecord();
    },

    makeRankingTable: function (data) {
        var list_html = '';
        var html = '';

        for (var i = 0; i < data.root.length; i++) {
            html = '\
	<tr>\
		<td class="bg01 rank"><span><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" /><-ONLINE_ID-></a></span></td>\
		<td class="bg01"><span><-SCORE-></span></td>\
		<td class="bg02"><span><-UPDATE_TIME-></span></td>\
	</tr>\
			';
            html = html.replace(/<-INDEX->/g, i + 1);
            html = html.replace(/<-RANK->/g, data.root[i].rank);
            html = html.replace(/<-ONLINE_ID->/g, data.root[i].online_id);
            html = html.replace(/<-COUNTRY->/g, data.root[i].country);
            html = html.replace(/<-SCORE->/g, data.root[i].score);
            html = html.replace(/<-UPDATE_TIME->/g, data.root[i].local_time);
            list_html += html;

            this.ranking_detail_data[i + 1] = {
                online_id: data.root[i].online_id,
                country: data.root[i].country,
                local_time: data.root[i].local_time,
                car_name: data.root[i].car_name,
                transmission: data.root[i].transmission,
                front_tire: data.root[i].front_tire,
                rear_tire: data.root[i].rear_tire,
                tcs: data.root[i].tcs,
                professional: data.root[i].professional,
                active_steering: data.root[i].active_steering,
                asm: data.root[i].asm,
                abs: data.root[i].abs,
                controller_type: data.root[i].controller_type
            };
        }
        return list_html;
    },

    makeRankingTableTotal: function (data) {
        var list_html = '';
        var html = '';

        for (var i = 0; i < data.root.length; i++) {
            html = '\
	<tr>\
		<td class="bg01 rank"><span><-RANK-></span></td>\
		<td class="bg02 onlineid"><span><a href="javascript:void(0);" onclick="popup.openRankingDetail(<-INDEX->)"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" width="18" height="12" alt="$rank.country" /><-ONLINE_ID-></a></span></td>\
		<td class="bg01"><span><-SCORE1-></span></td>\
		<td class="bg01"><span><-SCORE2-></span></td>\
';
            if (this.academy_round == 0) {
                html += '<td class="bg01"><span><-SCORE3-></span></td>';
            }
            html += '\
		<td class="bg02"><span><-SCORE-></span></td>\
	</tr>\
			';
            html = html.replace(/<-INDEX->/g, i + 1);
            html = html.replace(/<-RANK->/g, data.root[i].rank);
            html = html.replace(/<-ONLINE_ID->/g, data.root[i].online_id);
            html = html.replace(/<-COUNTRY->/g, data.root[i].country);
            html = html.replace(/<-SCORE1->/g, data.root[i].score_list[0]);
            html = html.replace(/<-SCORE2->/g, data.root[i].score_list[1]);
            html = html.replace(/<-SCORE3->/g, data.root[i].score_list[2]);
            html = html.replace(/<-SCORE->/g, data.root[i].score);
            list_html += html;

            this.ranking_detail_data[i + 1] = {
                online_id: data.root[i].online_id,
                country: data.root[i].country,
                local_time: data.root[i].local_time,
                car_name: data.root[i].car_name,
                transmission: data.root[i].transmission,
                front_tire: data.root[i].front_tire,
                rear_tire: data.root[i].rear_tire,
                tcs: data.root[i].tcs,
                professional: data.root[i].professional,
                active_steering: data.root[i].active_steering,
                asm: data.root[i].asm,
                abs: data.root[i].abs,
                controller_type: data.root[i].controller_type
            };
        }
        return list_html;
    },

    getLoadingHtml: function () {
        var html = this.getTableHeaderHtml();
        html += '\
<tr>\
	<td colspan="4">Loading...</td>\
</tr>\
		';
        html = html.replace(/<-LOCALE_URL->/g, this.locale_url);
        return html;
    },

    getTableHeaderHtml: function () {
        return '\
<tr class="header">\
	<th class="rank"><div><p class="ranking_loading" id="ranking_loading"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></p><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_rank.png" class="iepngfix" height="20" width="74" alt="Rank" /></div></th>\
	<th class="onlineid"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_id.png" class="iepngfix" height="20" width="133" alt="Online ID" /></div>\</th>\
	<th class="time"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_time.png" class="iepngfix" height="20" width="45" alt="Time" /></div></th>\
	<th class="update"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_update.png" class="iepngfix" height="20" width="84" alt="Update" /></div></th>\
</tr>\
<tr id="myrecord">\
	<td class="self rank">- - -</td>\
	<td class="bg02 onlineid"><div id="caption">My Record</div></td>\
	<td class="bg01">- - -</td>\
	<td class="bg02">- - -</td>\
</tr>\
		'.replace(/<-LOCALE_URL->/g, this.locale_url);
    },

    getTableHeaderHtmlTotal: function () {
        var html = '\
<tr class="header">\
	<th class="rank"><div><p class="ranking_loading" id="ranking_loading"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></p><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_rank.png" class="iepngfix" height="20" width="74" alt="Rank" /></div></th>\
	<th class="onlineid"><div><img src="/local/<-LOCALE_URL->/images/gt5p/ranking/t_id.png" class="iepngfix" height="20" width="133" alt="Online ID" /></div>\</th>\
';
        if (this.academy_round == 0) {
            html += '\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_1_1.png" class="iepngfix" height="20" width="80" alt="Rd.1-1" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_1_2.png" class="iepngfix" height="20" width="80" alt="Rd.1-2" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_1_3.png" class="iepngfix" height="20" width="80" alt="Rd.1-3" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_total.png" class="iepngfix" height="20" width="68" alt="Total" /></div></th>\
';
        }
        else if (this.academy_round == 1) {
            html += '\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_2_1.png" class="iepngfix" height="20" width="80" alt="Rd.2-1" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_2_2.png" class="iepngfix" height="20" width="80" alt="Rd.2-2" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_total.png" class="iepngfix" height="20" width="68" alt="Total" /></div></th>\
';
        }
        else if (this.academy_round == 2) {
            html += '\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_3_1.png" class="iepngfix" height="20" width="80" alt="Rd.2-1" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_3_2.png" class="iepngfix" height="20" width="80" alt="Rd.2-2" /></div></th>\
	<th class="totaltime"><div><img src="/local/<-LOCALE_URL->/images/academy/ranking/t_total.png" class="iepngfix" height="20" width="68" alt="Total" /></div></th>\
';
        }
        html += '\
</tr>\
		'.replace(/<-LOCALE_URL->/g, this.locale_url);

        if (this.result_json_name == "") {
            html += '\
<tr id="myrecord">\
	<td class="self rank">- - -</td>\
	<td class="bg02 onlineid"><div id="caption">My Record</div></td>\
	<td class="bg01">- - -</td>\
	<td class="bg01">- - -</td>\
';

            if (this.academy_round == 0)
                html += '<td class="bg01">- - -</td>';

            html += '\
	<td class="bg02">- - -</td>\
</tr>\
			';
        }
        return html;
    }

});

/*-------*/
/* PHOTO */
/*-------*/
var GT5Photo = Class.create();
Object.extend(GT5Photo.prototype, GT5Ajax.prototype);
Object.extend(GT5Photo.prototype,
{
    request_url: "",
    max_length: 8,

    GET_LIST: 0,
    EDIT: 1,

    initialize: function (locale_url) {
        this.request_url = '/' + locale_url + '/api/gt5/photo/';
    },

    complete: function (res) {
        var data = res.evalJSON();
        var list_html = '';
        var data_length = data.root.length;

        if (data_length > this.max_length)
            data_length = this.max_length;

        photo_data_list = new Array(data_length);
        if (this.job == this.EDIT) {
            popup.closePopup();
            for (var i = 0; i < data_length; i++) {
                photo_data_list[i] = data.root[i];
                if (this.photo_id == photo_data_list[i].photo_id)
                    popup.openOnlinePhoto(i);
            }
        }
        else if (this.job == this.GET_LIST) {
            for (var i = 0; i < data_length; i++) {
                list_html += this.getPhotoListHtml(data.root[i], i);
                photo_data_list[i] = data.root[i];
            }
            for (; i < this.max_length; i++) {
                list_html += '<dd>&nbsp;</dd>';
            }
            list_html += '<dd class="top_shadow">&nbsp;</dd>';
            $('gt5_photo').innerHTML = list_html;
        }
    },
    getPhotoList: function () {
        if (service_read_photo == 0) {
            this.job = this.GET_LIST;
            this.pars = $H({ online_id: target_profile.id }).toQueryString();
            this.execute();
        }
    },
    editComment: function (photo_id) {
        $('popup_button_off_ok').style.display = "inline";
        $('popup_button_off_cancel').style.display = "inline";
        //		$('popup_photo_edit_button').innerHTML='<img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" />';
        this.photo_id = photo_id
        this.job = this.EDIT;
        this.pars = $H({ job: this.job, photo_id: this.photo_id, comment: $('photo_comment').value.replace(/[\n\r]/g, '') }).toQueryString();
        this.execute();
    },
    getPhotoListHtml: function (data, index) {
        var html = '<dd><a href="javascript:void(0)" onclick="popup.openOnlinePhoto(<-INDEX->)"><img src="<-BASE_URL-><-PHOTO_ID->_2.jpg" with="92" height="92" /></a><span><-CREATE_TIME-></span></dd>';
        html = html.replace(/<-BASE_URL->/g, photo_base_url);
        html = html.replace(/<-PHOTO_ID->/g, data.photo_id);
        html = html.replace(/<-INDEX->/g, index);
        //		var create_time = Date.parseExact(data.create_time, 'yyyy-MM-ddTHH:mm:ssZ');
        var create_time = Date.parseExact(data.local_time, 'yyyy/MM/dd HH:mm:ss');
        html = html.replace(/<-CREATE_TIME->/g, create_time.format(localize_common_datetime_format_short));
        return html;
    }
});

/*-------*/
/* COURSE */
/*-------*/
var GT5Course = Class.create();
Object.extend(GT5Course.prototype, GT5Ajax.prototype);
Object.extend(GT5Course.prototype,
{
    request_url: "",
    max_length: 2,

    GET_LIST: 0,
    EDIT: 1,

    TOSCANA: "575a44fef867baf3b2f8f5714c9e32d9",
    EIFEL_CIRCUIT: "19bd586a1aa3ea5e122d1b8dbe12de53",
    ASO: "ac16bb771ae6ed4acdfccbdf948822ce",
    LIEGE: "5c1921570400406b2931373f25b69c23",
    ALASKA: "f8a17a80341d48cb46fa2fd78fa08a4d",
    EIFEL_KART: "2b3c11afd09cce0e72186b76bca54337",
    TOKYO: "5896442f3a2490c4ff8164ff6a2ccb59",

    initialize: function (locale_url) {
        this.request_url = '/' + locale_url + '/api/gt5/course/';
    },

    complete: function (res) {
        var data = res.evalJSON();
        var list_html = '';
        var data_length = data.root.length;

        if (data_length > this.max_length)
            data_length = max_length;

        course_data_list = new Array(data_length);

        if (this.job == this.EDIT) {
            popup.closePopup();
            for (var i = 0; i < data_length; i++) {
                course_data_list[i] = data.root[i];
                if (this.course_id == course_data_list[i].course_id)
                    popup.openOnlineCourse(i);
            }
        }
        else if (this.job == this.GET_LIST) {
            for (var i = 0; i < data_length; i++) {
                list_html += this.getCourseListHtml(data.root[i], i);
                course_data_list[i] = data.root[i];
            }
            for (; i < this.max_length; i++) {
                list_html += '<dd>&nbsp;</dd>';
            }
            list_html += '<dd class="top_shadow">&nbsp;</dd>';
            $('gt5_course').innerHTML = list_html;
        }
    },
    getCourseList: function () {
        if (service_read_course == 0) {
            this.job = this.GET_LIST;
            this.pars = $H({ online_id: target_profile.id }).toQueryString();
            this.execute();
        }
    },
    editComment: function (course_id) {
        $('popup_button_off_ok').style.display = "inline";
        $('popup_button_off_cancel').style.display = "inline";
        //		$('popup_course_edit_button').innerHTML='<img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" />';
        this.course_id = course_id
        this.job = this.EDIT;
        this.pars = $H({ job: this.job, course_id: this.course_id, comment: $('course_comment').value.replace(/[\n\r]/g, '') }).toQueryString();
        this.execute();
    },
    getCourseListHtml: function (data, index) {
        var html = '<dd class="base"><a href="javascript:void(0)" onclick="popup.openOnlineCourse(<-INDEX->)"><img src="<-BASE_URL-><-PHOTO_ID->_0.png" width="92" /><img class="clock" src="/common/images/gt5/course/icon_clock_s.png" width="22" height="22" alt="clock" /><img class="weather" src="/common/images/gt5/course/icon_weather_<-WEATHER->_s.png" width="22" height="22" alt="weather" /></a><span><-CREATE_TIME-></span></dd>';
        html = html.replace(/<-BASE_URL->/g, photo_base_url);
        html = html.replace(/<-PHOTO_ID->/g, data.thumbnail_photo_id);
        html = html.replace(/<-WEATHER->/g, data.weather);
        html = html.replace(/<-INDEX->/g, index);
        //		var create_time = Date.parseExact(data.create_time, 'yyyy-MM-ddTHH:mm:ssZ');
        var create_time = Date.parseExact(data.local_time, 'yyyy/MM/dd HH:mm:ss');
        html = html.replace(/<-CREATE_TIME->/g, create_time.format(localize_common_datetime_format_short));
        return html;
    }
});

/*-----*/
/* LOG */
/*-----*/
var GT5Log = Class.create();
Object.extend(GT5Log.prototype, GT5Ajax.prototype);
Object.extend(GT5Log.prototype,
{
    request_url: "",

    DISPLAY: 100, /*ï¼‘å›žã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆã§å–å¾—ã™ã‚‹ä»¶æ•°*/

    initialize: function (locale_url) {
        this.request_url = '/' + locale_url + '/api/gt5/log/';
        this.target_number = target_profile.number;
        this.target_online_id = target_profile.id;
        $('gt5mypage_contents').innerHTML = this.getLogBaseHtml();

        if (online_id == target_profile.id) {
            $('gt5_log').style.height = 681 + "px";
            //			$('gt5_log').style.height = 771 + "px";
        }
        else {
            $('community_menu').style.height = 1047 + "px";
            $('gt5_log').style.height = 823 + "px";
            //			$('gt5_log').style.height = 913 + "px";
        }
    },

    getFirstLog: function () {
        if (service_read_log != 0) {
            $('gt5_log').innerHTML = '<p class="maintenance">' + localize_gtcom_cannot_read + '</p>';
        }
        else {
            this.pars = $H({ online_id: this.target_online_id, user_number: this.target_number, count: this.DISPLAY }).toQueryString();
            this.execute();
        }
    },

    complete: function (res) {
        //alert(res);
        var data = res.evalJSON();
        var list_html = '';
        for (var i = 0; i < data.root.length; i++) {
            if (data.root[i].result_id) {
                if (this.friendCheck(data.root[i].online_id))
                    list_html += '<dl class="gt5_log"><dd class="log"><a href="javascript:void(0);" onclick="gt5bspec.openBspecWindowResultDetail(\'' + data.root[i].online_id + '\',\'' + data.root[i].result_id + '\')">' + data.root[i].value + '</a></dd><dd class="time">' + getDateDiffString(data.root[i].create_time, data.root[i].local_time) + '</dd></dl>';
                else
                    list_html += '<dl class="gt5_log"><dd class="log"><a href="javascript:void(0);" onclick="gt5bspec.openBspecWindowResultDetail(\'' + data.root[i].online_id + '\',\'' + data.root[i].result_id + '\',\'' + target_profile.id + '\')">' + data.root[i].value + '</a></dd><dd class="time">' + getDateDiffString(data.root[i].create_time, data.root[i].local_time) + '</dd></dl>';
            }
            else
                list_html += '<dl class="gt5_log"><dd class="log">' + data.root[i].value + '</dd><dd class="time">' + getDateDiffString(data.root[i].create_time, data.root[i].local_time) + '</dd></dl>';
        }
        if (data.root.length == 0) {
            list_html += '\
	<dl class="list_nodata">\
		<dd><img src="/common/images/gt5/no_data.png" width="68" height="68" /></dd>\
		<dd>' + localize_common_nodata + '</dd>\
	</dl>\
			';
        }
        $('gt5_log').innerHTML = list_html;
        fleXenv.fleXcrollMain("gt5_log");
    },

    friendCheck: function (check_id) {
        for (i = 0; i < friend_id_list.length; i++) {
            if (friend_id_list[i] == check_id)
                return true;
        }
        return false;
    },

    getLogBaseHtml: function () {
        return '<p class="gt5_myhome_menu_hr" style="font-size:1px;"><img src="/common/images/gt5/main_hr.png" /><p><div id="gt5_log"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></div>';
    }
});

/*------*/
/* Mail */
/*------*/
var GT5Mail = Class.create();
Object.extend(GT5Mail.prototype, GT5Ajax.prototype);
Object.extend(GT5Mail.prototype,
{
    request_url: "",
    locale_url: "",
    GET_INCOMING: 0,
    GET_SEND: 1,
    GET_INCOMING_MORE: 2,
    DEL_INCOMING: 3,
    DEL_SEND: 4,
    SEND_EXEC: 5,

    DISPLAY: 100, /*ï¼‘å›žã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆã§å–å¾—ã™ã‚‹ä»¶æ•°*/

    initialize: function (locale_url) {
        this.locale_url = locale_url;
        this.opened_mail_id = 0;
        this.request_url = '/' + locale_url + '/api/gt5/mail/';
    },

    complete: function (res) {
        if (this.job == this.GET_INCOMING || this.job == this.GET_SEND) {
            var data = res.evalJSON();
            var list_html = '';

            var data_length = data.root.length;
            if (isMSIE)
                data_length -= 0;

            for (var i = 0; i < data_length; i++) {
                list_html += this.getMailListHtml(data.root[i], this.job);
            }

            if (data.root.length == 0) {
                list_html += '\
		<dl class="list_nodata">\
			<dd><img src="/common/images/gt5/no_data.png" width="68" height="68" /></dd>\
			<dd>' + localize_common_nodata + '</dd>\
		</dl>\
				';
            }

            $('gt5_mail').innerHTML = list_html;
        }
        else if (this.job == this.SEND_EXEC) {
            popup.closePopup();
        }
        else if (this.job == this.DEL_INCOMING || this.job == this.DEL_SEND) {
            /*
            è¦‹ãŸç›®çš„ãªå‰Šé™¤å‡¦ç†
            */
            var delete_data = $('gt5_mail_' + this.delete_mail_id);
            delete_data.style.display = "none";
            popup.closePopup();
        }
        fleXenv.fleXcrollMain("gt5_mail");
    },

    getFirstLog: function () {
        this.opened_mail_id = 0;
        $('gt5mypage_contents').innerHTML = this.getMailBaseHtml();

        //		$('gt5_mail').style.height = 705 + "px";
        $('gt5_mail').style.height = 615 + "px"; //705

        $('mail_button_switch_receive').innerHTML = '<img src="/local/' + this.locale_url + '/images/gt5/buttons/button_receive_a.png" height="31" alt="' + localize_mail_receivebox + '" />';
        $('mail_button_switch_send').innerHTML = '<img src="/local/' + this.locale_url + '/images/gt5/buttons/button_send_b.png" height="31" alt="' + localize_mail_sendbox + '" />';
        if (service_read_mail != 0) {
            $('gt5_mail').innerHTML = '<p class="maintenance">' + localize_gtcom_cannot_read + '</p>';
        }
        else {
            this.job = this.GET_INCOMING;
            this.pars = $H({ job: this.job, count: this.DISPLAY }).toQueryString();
            this.execute();
        }
    },
    getSendlistLog: function () {
        this.opened_mail_id = 0;
        $('gt5mypage_contents').innerHTML = this.getMailBaseHtml();

        //		$('gt5_mail').style.height = 705 + "px";
        $('gt5_mail').style.height = 615 + "px"; //705

        $('mail_button_switch_receive').innerHTML = '<img src="/local/' + this.locale_url + '/images/gt5/buttons/button_receive_b.png" height="31" alt="' + localize_mail_receivebox + '" />';
        $('mail_button_switch_send').innerHTML = '<img src="/local/' + this.locale_url + '/images/gt5/buttons/button_send_a.png" height="31" alt="' + localize_mail_sendbox + '" />';
        if (service_read_mail != 0) {
            $('gt5_mail').innerHTML = '<p class="maintenance">' + localize_gtcom_cannot_read + '</p>';
        }
        else {
            this.job = this.GET_SEND;
            this.pars = $H({ job: this.job }).toQueryString();
            this.execute();
        }
    },
    sendMessage: function () {
        $('submit_mail_button').style.display = "inline";
        $('cancel_mail_button').style.display = "inline";

        var message_send_to = $('send_message_to').value;
        var message_subject = $('send_message_subject').value;
        var message_body = $('send_message_body').value;
        this.job = this.SEND_EXEC;
        this.pars = $H({ job: this.job, to: message_send_to, subject: message_subject, body: message_body }).toQueryString();
        this.execute();
    },
    deleteMessage: function (mail_id, delete_type) {
        $('update_profile_button').style.display = "inline";
        $('cancel_profile_button').style.display = "inline";
        this.delete_mail_id = mail_id;
        if (delete_type == "receive")
            this.job = this.DEL_INCOMING
        else if (delete_type == "send")
            this.job = this.DEL_SEND
        this.pars = $H({ job: this.job, mail_id: mail_id }).toQueryString();
        this.execute();
    },

    getMailBaseHtml: function () {
        var html = '\
	<dl class="mailbox_selector">\
		<dd class="mail_new"><a href="javascript:void(0);" onclick="popup.openDirectMessage(null,true);"><img src="/local/' + this.locale_url + '/images/gt5/buttons/button_new.png" height="31" alt="New" /></a></dd>\
		<dd class="mail_send_receive">\
			<a href="javascript:void(0);" id="mail_button_switch_receive" onclick="gt5contents.getFirstLog();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/button_receive_a.png" height="31" alt="' + localize_mail_receivebox + '" /></a><a href="javascript:void(0);" id="mail_button_switch_send" onclick="gt5contents.getSendlistLog();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/button_send_b.png" height="31" alt="' + localize_mail_sendbox + '" /></a>\
		</dd>\
	</dl>\
		<p class="gt5_contents_main_hr"><img src="/common/images/gt5/main_hr.png" /><p>\
	<div id="gt5_mail"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></div>\
		';

        return html;
    },

    getMailListHtml: function (data, job_id) {
        var reg = '';
        var html = '<dl class="gt5_mail_item" id="gt5_mail_<-MAIL_ID->">';
        if (job_id == this.GET_INCOMING)
            html += '<dd class="from"><span class="mail_name">' + localize_mail_from + ' : <a href="javascript:void(0);" onclick="popup.openProfile(\'<-USER_ID_FROM->\')"><-USER_ID_FROM-></a></span><span class="mail_date"><-CREATE_TIME-></span></dd>';
        else if (job_id == this.GET_SEND)
            html += '<dd class="from"><span class="mail_name">' + localize_mail_to + ' : <a href="javascript:void(0);" onclick="popup.openProfile(\'<-USER_ID_TO->\')"><-USER_ID_TO-></a></span><span class="mail_date"><-CREATE_TIME-></span></dd>';
        html += '\
		<dt id="message_subject_<-MAIL_ID->"><a href="javascript:void(0);" onclick="gt5mail.openMessageBody(<-MAIL_ID->)"><span><-MESSAGE_SUBJECT-></span></a></dt>\
		<dd class="message_body" id="message_body_<-MAIL_ID->">\
			<p><pre><-MESSAGE_BODY-></pre></p><div class="mail_footer">\
		';
        if (this.job == this.GET_INCOMING || this.job == this.GET_INCOMING_MORE)
            html += '\<span class="delete"><a href="javascript:void(0);" onclick="popup.openDeleteCheck(<-MAIL_ID->, \'receive_mail\')">' + localize_mail_delete + '</a></span>';
        else if (this.job == this.GET_SEND)
            html += '\<span class="delete"><a href="javascript:void(0);" onclick="popup.openDeleteCheck(<-MAIL_ID->, \'send_mail\')">' + localize_mail_delete + '</a></span>';

        if (job_id == this.GET_INCOMING)
            html += '&nbsp;<span class="reply"><a href="javascript:void(0);" onclick=\'popup.openDirectMessage("<-USER_ID_FROM->",false,"<-MAIL_ID->")\'>' + localize_mail_reply + '</a></span>';
        html += '\
		</div></dd>\
	</dl>\
		';
        html = html.replace(/<-MAIL_ID->/g, data.mail_id);
        html = html.replace(/<-USER_ID_FROM->/g, data.from);
        html = html.replace(/<-USER_ID_TO->/g, data.to);
        if (data.local_time)
            html = html.replace(/<-CREATE_TIME->/g, getDateDiffString(data.create_time, data.local_time));
        reg = new RegExp(/^\s+$/);
        html = html.replace(/<-MESSAGE_SUBJECT->/g, data.subject != "" && !reg.test(data.subject) ? data.subject.replace(/\$/g, '&#36;').replace(/'/g, '\&#39;').replace(/ /g, '&nbsp;') : localize_mail_no_title);
        html = html.replace(/<-MESSAGE_BODY->/g, data.body != "" ? data.body.replace(/\n/g, "<br/>").replace(/\$/g, '&#36;').replace(/ /g, '&nbsp;') : localize_mail_no_comment);
        html = html.replace(/<-JOB_ID->/g, this.job);

        eval("mail_subject_" + data.mail_id + " = '" + data.subject.replace(/\$/g, '&#36;').replace(/'/g, '\&#39;') + "';");

        return html;
    },

    openMessageBody: function (mail_id) {
        if (this.opened_mail_id != 0 && $('message_body_' + this.opened_mail_id)) {
            $('message_body_' + this.opened_mail_id).className = 'message_body';
            $('message_subject_' + this.opened_mail_id).className = '';
        }

        if (mail_id == this.opened_mail_id) {
            $('message_body_' + this.opened_mail_id).className = 'message_body';
            $('message_subject_' + this.opened_mail_id).className = '';
            this.opened_mail_id = 0;
        }
        else {
            $('message_body_' + mail_id).className = 'message_body mail_selected';
            $('message_subject_' + mail_id).className = 'selected';
            this.opened_mail_id = mail_id;
        }
        fleXenv.fleXcrollMain("gt5_mail");
    }
});

/*------*/
/* Gift */
/*------*/
var GT5Gift = Class.create();
Object.extend(GT5Gift.prototype, GT5Ajax.prototype);
Object.extend(GT5Gift.prototype,
{
    request_url: "",
    DISPLAY: 50,

    initialize: function (locale_url) {
        this.request_url = '/' + locale_url + '/api/gt5/itembox/';
        this.target_online_id = target_profile.id;
        var contents_html = this.getGiftBaseHtml();
        $('gt5mypage_contents').innerHTML = contents_html;

        if (online_id == target_profile.id) {
            $('gt5_gift').style.height = 662 + "px";
            //			$('gt5_gift').style.height = 752 + "px";
        }
    },

    complete: function (res) {
        var data = res.evalJSON();
        var list_html = '';
        var type_icon = '';

        if (data.root.length > 0)
            list_html += '';

        for (var i = 0; i < data.root.length; i++) {
            list_html += '\
	<dl class="gt5_gift">\
		<dd class="gift_icon"><img src="/common/images/gt5/gift/icon/<-TYPE_ICON->" width="62" height="48" /></dd>\
		<dd><span>' + localize_mail_from + '</span> <a href="javascript:void(0);" onclick="popup.openProfile(\'<-SENDER_ID->\')"><-SENDER_ID-></a></dd>\
		<dd class="comment"><-COMMENT-></dd>\
		<dd class="type_name"><-TYPE_NAME-></dd>\
		<dd class="time"><-CREATE_TIME-></dd>\
	</dl>\
			';

            if (data.root[i].type == 7)
                type_icon = "museum.png";
            else
                type_icon = "item.png";

            list_html = list_html.replace(/<-TYPE_ICON->/g, type_icon);
            list_html = list_html.replace(/<-SENDER_ID->/g, data.root[i].sender);
            list_html = list_html.replace(/<-COMMENT->/g, data.root[i].comment != "" ? data.root[i].comment.replace(/\$/g, '&#36;') : localize_gift_comment_empty);
            list_html = list_html.replace(/<-TYPE_NAME->/g, data.root[i].type_name);
            list_html = list_html.replace(/<-CREATE_TIME->/g, getDateDiffString(data.root[i].create_time, data.root[i].local_time));
        }

        if (data.root.length == 0) {
            list_html += '\
	<dl class="list_nodata">\
		<dd><img src="/common/images/gt5/no_data.png" width="68" height="68" /></dd>\
		<dd>' + localize_common_nodata + '</dd>\
	</dl>\
			';
        }

        $('gt5_gift').innerHTML = list_html;
        fleXenv.fleXcrollMain("gt5_gift");
    },

    getFirstLog: function () {
        if (service_read_itembox != 0) {
            $('gt5_gift').innerHTML = '<p class="maintenance">' + localize_gtcom_cannot_read + '</p>';
        }
        else {
            this.pars = $H({ online_id: this.target_online_id, count: this.DISPLAY }).toQueryString();
            this.execute();
        }
    },

    getGiftBaseHtml: function () {
        var html = '\
	<p class="gift_main_notice">' + localize_gtcom_gift_caution + '</p>\
	<p class="gt5_myhome_menu_hr gift" style="font-size:1px;"><img src="/common/images/gt5/main_hr.png" /></p>\
	<div id="gt5_gift"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></div>\
		';
        return html;
    }
});

/*-----*/
/* BBS */
/*-----*/
var GT5Bbs = Class.create();
Object.extend(GT5Bbs.prototype, GT5Ajax.prototype);
Object.extend(GT5Bbs.prototype,
{
    request_url: "",
    locle_url: "",
    FIRST_READ: 0,
    MORE_READ: 1,
    WRITE: 2,
    DELETE: 3,

    DISPLAY: 99, /*ï¼‘å›žã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆã§å–å¾—ã™ã‚‹ä»¶æ•°*/

    initialize: function (locale_url) {
        this.locale_url = locale_url;
        this.request_url = '/' + locale_url + '/api/gt5/bbs/';
        this.bbs_board_id = target_profile.number;
        this.bbs_online_id = target_profile.id;

        $('gt5mypage_contents').innerHTML = this.getBbsBaseHtml();

        fleXenv.fleXcrollMain("gt5_bbs_comment");

        if (service_read_bbs == 0) {
            if (online_id == target_profile.id) {
                $('gt5_bbs_comment').style.height = 547 + "px";
                //				$('gt5_bbs_comment').style.height = 637 + "px";
            }
            else {
                $('community_menu').style.height = 1047 + "px";
                $('gt5_bbs_comment').style.height = 689 + "px";
                //				$('gt5_bbs_comment').style.height = 779 + "px";
            }
        }
        else {
            if (online_id == target_profile.id)
                $('gt5_bbs_input_stop').style.height = 830 + "px";
            else
                $('gt5_bbs_input_stop').style.height = 966 + "px";
        }
    },

    success: function (res) {
        if (this.job == this.DELETE) {
            var delete_data = $('gt5bbs_' + this.delete_comment_id);
            delete_data.style.display = "none";
            popup.closePopup();
        }
        else {
            this.updateBbsField(res.evalJSON());
        }
        fleXenv.fleXcrollMain("gt5_bbs_comment");
        Event.observe('bbs_input', 'keyup', function (e) { textCounter("bbs_input") });
    },

    getBbsCache: function () {
        if (service_read_bbs == 0) {
            this.job = this.FIRST_READ;
            this.pars = $H({ job: this.job, bbs_board_id: this.bbs_board_id, online_id: this.bbs_online_id, count: this.DISPLAY + 1 }).toQueryString();
            this.execute();
        }
    },

    getBbsData: function (comment_id) {
        if (service_read_bbs == 0) {
            this.job = this.MORE_READ;
            this.pars = $H({ job: this.job, bbs_board_id: this.bbs_board_id, online_id: this.bbs_online_id, bbs_comment_id: comment_id, count: this.DISPLAY + 1 }).toQueryString();
            this.execute();
        }
    },

    deleteBbsData: function (comment_id) {
        $('update_profile_button').style.display = "inline";
        $('cancel_profile_button').style.display = "inline";
        this.job = this.DELETE;
        this.delete_comment_id = comment_id;
        this.pars = $H({ job: this.job, bbs_board_id: this.bbs_board_id, online_id: this.bbs_online_id, bbs_comment_id: comment_id }).toQueryString();
        this.execute();
    },

    postBbsData: function () {
        //		$('gt5_bbs_submit').innerHTML = "";
        $('bbs_submit_button').style.display = "block";
        $('gt5_bbs_comment').fleXcroll.setScrollPos(false, 0);
        $('bbs_writhig_wait').style.display = "block";
        this.job = this.WRITE;
        var bbs_input = $('bbs_input');
        this.pars = $H({ job: this.job, bbs_board_id: this.bbs_board_id, online_id: this.bbs_online_id, comment: bbs_input.value, count: this.DISPLAY + 1 }).toQueryString();
        this.execute();
    },

    updateBbsField: function (data) {
        var list_html = '';
        var data_length = data.root.length;

        if (data_length == this.DISPLAY + 1) {
            data_length -= 1;
        }

        list_html += '<dl id="bbs_writhig_wait"><dd style="text-align:center;"><img src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></dd></dl>';

        for (i = 0; i < data_length; i++) {
            list_html += this.getBbsListHtml(data.root[i]);
        }

        if (data.root.length == 0) {
            list_html += '\
	<dl class="list_nodata">\
		<dd><img src="/common/images/gt5/no_data.png" width="68" height="68" /></dd>\
		<dd>' + localize_common_nodata + '</dd>\
	</dl>\
			';
        }

        this.job == this.MORE_READ ?
			$('result').innerHTML += list_html :
			$('result').innerHTML = list_html;

        var getmore = $('gt5_bbs_getmore');
        data.root.length == (this.DISPLAY + 1) ?
			getmore.innerHTML = this.getBbsGetMoreHtml(data.root[i - 1]) :
			getmore.innerHTML = '';

        /*
        å…¥åŠ›ãƒ•ã‚£ãƒ¼ãƒ«ãƒ‰ã®åˆæœŸåŒ–
        */
        if (this.job == this.WRITE) {
            $('bbs_characters_counter').innerHTML = "0 / 140";
            $('bbs_input').value = "";
        }
        //		$('gt5_bbs_submit').innerHTML = '<a href="javascript:void(0);" onclick="gt5contents.postBbsData()";><img src="/local/'+this.locale_url+'/images/gt5/buttons/button_bbs_submit.png" height="32" /></a>';

        //		$('bbs_submit_button').style.display = "none";
        //		$('bbs_writhig_wait').style.display = "none";
    },

    getBbsBaseHtml: function () {
        var html = '';

        if (service_read_bbs != 0) {
            html += '\
		<p style="text-align:center; font-size:1px; margin-top:44px;"><img src="/common/images/gt5/main_hr.png" /><p>\
		<div class="gt5_bbs_input_stop" id="gt5_bbs_input_stop">\
			<p>' + localize_gtcom_cannot_read + '</p>\
		</div>\
			';
        }
        else if (service_write_bbs == 0) {
            html += '\
		<div class="gt5_bbs_input">\
		<form>\
			<span id="bbs_characters_counter">0 / 140</span>\
			<textarea type="input" id="bbs_input" name="bbs_comment" rows="3"></textarea>\
			<span id="gt5_bbs_submit"><a href="javascript:void(0);" onclick="gt5contents.postBbsData()";><img src="/local/' + this.locale_url + '/images/gt5/buttons/button_bbs_submit.png" height="32" /></a></span><img class="bbs_submit_button" id="bbs_submit_button" src="/local/' + this.locale_url + '/images/gt5/buttons/button_bbs_submit_off.png" height="32" />\
		</form>\
		</div>\
		<p class="gt5_contents_main_hr"><img src="/common/images/gt5/main_hr.png" /><p>\
			';
        }
        else {
            html += '\
		<div class="gt5_bbs_input_stop" id="gt5_bbs_input_stop">\
			<p>' + localize_gtcom_cannot_write + '</p>\
		</div>\
		<p class="gt5_contents_main_hr"><img src="/common/images/gt5/main_hr.png" /><p>\
			';
        }

        if (service_read_bbs == 0) {
            html += '\
			<div class="gt5_bbs_comment flexcroll" id="gt5_bbs_comment">\
				<div id="result"><img class="loading_icon" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></div>\
				<div id="gt5_bbs_getmore">&nbsp;</div>\
			</div>\
			';
        }

        return html;
    },
    getBbsListHtml: function (data) {
        var diff_string = getDateDiffString(data.create_time, data.local_time);

        var html = '\
<dl id="gt5bbs_<-BBS_COMMENT_ID->">\
	<dt><a href="javascript:void(0);" onclick="popup.openProfile(\'<-USER_ID->\')" id="bbs_reply_id_<-BBS_COMMENT_ID->"><-USER_ID-></a></dt><dd class="gt_bbs_comment"><pre id="bbs_reply_comment_<-BBS_COMMENT_ID->"><-BBS_COMMENT-></pre></dd>\
	<dd class="option"><span class="time">' + diff_string + '</span>\
		';
        if (online_id == target_profile.id || online_id == data.user_id)
            html += '\
	<span class="delete" id="bbs_delete_<-BBS_COMMENT_ID->"><a href="javascript:void(0);" onclick="gt5contents.reply(<-BBS_COMMENT_ID->)">' + localize_format_bbs_reply + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="popup.openDeleteCheck(<-BBS_COMMENT_ID->,\'bbs\')">' + localize_format_bbs_delete + '</a></span>\
		';
        else
            html += '\
	<span class="delete" id="bbs_delete_<-BBS_COMMENT_ID->"><a href="javascript:void(0);" onclick="gt5contents.reply(<-BBS_COMMENT_ID->)">' + localize_format_bbs_reply + '</a></span>\
		';
        html += '</dd></dl>';

        html = html.replace(/<-BBS_COMMENT_ID->/g, data.bbs_comment_id);
        html = html.replace(/<-USER_ID->/g, data.user_id);
        html = html.replace(/<-BBS_COMMENT->/g, textReEscape(data.comment.replace(/\n/g, "<br/>").replace(/\$/g, '&#36;').replace(/ /g, '&nbsp;')));
        return html;
    },

    getBbsGetMoreHtml: function (data) {
        return '<a href="javascript:void(0);" onclick="gt5contents.getBbsData(' + data.bbs_comment_id + ');">Get More</a>';
    },

    reply: function (bbs_comment_id) {
        $('bbs_input').value += localize_format_bbs_reply_format.replace('%1$s', $("bbs_reply_id_" + bbs_comment_id).innerHTML).replace('%2$s', $("bbs_reply_comment_" + bbs_comment_id).innerHTML.replace(/<br>/g, "\n").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&nbsp;/g, ' ').replace(/\$/g, '&#36;'));
        $('bbs_input').value = $('bbs_input').value.replace(/&#36;/g, '$');
        textCounter("bbs_input");
    }
});

/*------------*/
/* RemoteRace */
/*------------*/
var GT5Bspec = Class.create();
Object.extend(GT5Bspec.prototype, GT5Ajax.prototype);
Object.extend(GT5Bspec.prototype,
{
    request_url: "",
    locale_url: "",

    /* JOB */
    RESET: 0,
    GET_CARLIST: 1,
    GET_DRIVERLIST: 2,
    ADD_ENTRY: 3,
    REMOVE_ENTRY: 4,
    SELECT_EVENT: 5,
    GET_STATUS: 6,
    GO_RACE: 7,
    GET_MONITORLIST: 8,
    GET_RESULTLIST: 9,
    GET_RESULT: 10,
    GET_ENTRYLIST: 11,
    END_RACE: 12,

    /* MODE */
    EVENT_SELECT: 0,
    MATCHING: 1,
    CHECK: 2,
    RACE_MONITOR: 3,
    MYPAGE: 4,
    SUB_WINDOW: 5,
    MYHOME_PROFILE: 8,
    DEBUG: 9,

    matching_index_driver: 0,
    matching_index_car: 0,

    initialize: function (locale_url) {
        this.locale_url = locale_url;
        this.request_url = '/' + locale_url + '/api/gt5/remoterace/';
    },

    on400: function (res) {
        if (this.job == this.ADD_ENTRY) {
            gt5bspec.entryFailedDriverNameList.push(this.entry_driver_name);
        }
        else if (this.job == this.GO_RACE) {
            nowLoading(false);
            popup.remoteRaceGoRaceFailed();
        }
        else
            alert("400 error, JOB : " + this.job);
    },

    on599: function (res) {
        if (this.job == this.GET_MONITORLIST)
        { }
        else
            alert(localize_gtcom_cannot_read);
    },

    complete: function (res) {
        if (this.job == this.ADD_ENTRY) {
            added_list_size += 1;
            if (added_list_size == this.add_list_size) {
                added_list_size = 0;
                nowLoading(false);
                if (gt5bspec.entryFailedDriverNameList.length != 0) {
                    popup.driverEntryFailed(gt5bspec.entryFailedDriverNameList);
                }
            }
        }
    },

    success: function (res) {
        if (this.job == this.GET_CARLIST) {
            if (this.mode == this.MYHOME_PROFILE) {
                this.updateCarListForProfile(res.evalJSON());
            }
            else {
                this.updateCarListForMatching(res.evalJSON());
            }
        }
        else if (this.job == this.GET_DRIVERLIST) {
            if (this.mode == this.EVENT_SELECT) {
                this.updateDriverList(res.evalJSON());
            }
            else if (this.mode == this.MATCHING) {
                this.updateDriverListForMatching(res.evalJSON());
            }
            else if (this.mode == this.CHECK) {
                this.checkOnlineDriverResult(res.evalJSON());
            }
            else if (this.mode == this.MYHOME_PROFILE) {
                this.updateDriverListForProfile(res.evalJSON());
            }
        }
        else if (this.job == this.GET_STATUS) {
            if (this.mode == this.DEBUG) {
                alert(res);
            }
            else if (this.mode == this.RACE_MONITOR) {
                this.outputResultMode(res.evalJSON());
            }
            else if (this.mode == this.MYPAGE) {
                this.updateCheckStatusMypage(res.evalJSON());
            }
            else if (this.mode == this.SUB_WINDOW) {
                this.checkStatusSubWindow(res.evalJSON().status);
            }
        }
        else if (this.job == this.ADD_ENTRY) {
            this.updateEntry();
        }
        else if (this.job == this.GO_RACE) {
            this.updateGoRace();
        }
        else if (this.job == this.REMOVE_ENTRY) {
            this.updateRemoveEntry();
        }
        else if (this.job == this.GET_RESULTLIST) {
            this.updateResultList(res.evalJSON());
        }
        else if (this.job == this.GET_RESULT) {
            this.updateResultData(res.evalJSON());
        }
        else if (this.job == this.GET_MONITORLIST) {
            //			if(res != "[]")
            //				$('degug_log').innerHTML += res + "<br />";
            this.updateMonitorList(res.evalJSON());
        }
        else if (this.job == this.GET_ENTRYLIST) {
            alert(res);
        }
    },

    openBspecWindow: function () {
        var bspec_url = '/' + this.locale_url + '/gt5/user/' + target_profile.id + '/remoterace/';
        this.bspec_window = window.open(bspec_url, 'bspec_window', 'width=980, height=680, status=no, menubar=no, toolbar=no, resizable=no, scrollbars=no');
        this.bspec_window.focus();
    },

    openBspecWindowResult: function () {
        var bspec_url = '/' + this.locale_url + '/gt5/user/' + target_profile.id + '/remoterace/result/';
        this.bspec_window = window.open(bspec_url, 'bspec_window', 'width=980, height=680, menubar=no, toolbar=no, resizable=no, scrollbars=no');
        this.bspec_window.focus();
    },

    openBspecWindowResultDetail: function (online_id, result_id, friend_id) {
        if (friend_id != undefined)
            var bspec_url = '/' + this.locale_url + '/gt5/user/' + online_id + '/remoterace/result/d' + result_id + '.html?friend_id=' + friend_id;
        else
            var bspec_url = '/' + this.locale_url + '/gt5/user/' + online_id + '/remoterace/result/d' + result_id + '.html';

        this.bspec_window = window.open(bspec_url, 'bspec_window', 'width=980, height=680, menubar=no, toolbar=no, resizable=no, scrollbars=no');
        this.bspec_window.focus();
    },

    bspecReset: function () {
        this.job = this.RESET;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    checkEntryList: function () {
        this.job = this.GET_ENTRYLIST;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    getStatusDebug: function () {
        this.job = this.GET_STATUS;
        this.mode = this.DEBUG;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    /* CheckStatus Mypage */
    checkStatusMyPage: function () {
        this.job = this.GET_STATUS;
        this.mode = this.MYPAGE;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    updateCheckStatusMypage: function (data) {
        if (target_profile.id != online_id) {
            $('remoterace_status_informaition').innerHTML = localize_remoterace_result.replace(/XXXXX/g, target_profile.id);
            $('remoterace_status_icon').className = "status_icon";
        }
        else {
            if (data.status == 0) {
                $('remoterace_status_informaition').innerHTML = localize_remoterace_get_ready;
                $('remoterace_status_icon').className = "status_icon status0";
            }
            else if (data.status == 1) {
                $('remoterace_status_informaition').innerHTML = localize_remoterace_now_ready;
                $('remoterace_status_icon').className = "status_icon status1";
            }
            else if (data.status == 2 || data.status == 3) {
                $('remoterace_status_informaition').innerHTML = localize_remoterace_racing;
                $('remoterace_status_icon').className = "status_icon status2";
            }
        }
    },

    /* CheckStatus RemoteRace Window */
    checkStatusSubWindowUpdate: function () {
        this.job = this.GET_STATUS;
        this.mode = this.SUB_WINDOW;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    checkStatusSubWindow: function (remote_status) {
        this.status = remote_status;
        if (remote_status == 0) {
            $('remoterace_status_informaition').innerHTML = '<span>' + localize_remoterace_get_ready + '</span><a href="javascript:void(0);" onclick="popup.openRemoteRaceNotice();"><img src="/common/images/gt5/remote_race/common/footer/icon_help.png" /></a>';
        }
        else if (remote_status == 1) {
            $('remoterace_status_informaition').innerHTML = '<span>' + localize_remoterace_now_ready + '</span><img class="status_icon" src="/common/images/gt5/remote_race/mypage/status1.png" />';
        }
        else if (remote_status == 2 || remote_status == 3) {
            $('remoterace_status_informaition').innerHTML = '<a href="/' + this.locale_url + '/gt5/user/' + param_online_id + '/remoterace/"><span>' + localize_remoterace_racing + '</span><img src="/common/local/' + this.locale_url + '/images/gt5/remote_race/live.gif" height="40"></a>';
        }

    },

    /* Result */
    getResultList: function (target_online_id) {
        this.result_list_index = 0;
        this.target_online_id = target_online_id;
        this.job = this.GET_RESULTLIST;
        this.pars = $H({ job: this.job, online_id: this.target_online_id }).toQueryString();
        this.execute();
    },
    updateResultList: function (data) {
        var html = '';
        for (i = 0; i < data.length; i++) {
            html += '\
		<dl class="list">\
			<dd class="course"><img src="/common/images/gt5/remote_race/result_list/time_s/<-INFO_MINUTE->.png" width="40" height="28" /><p><-COURSE-><p></dd>\
			<dd class="laps"><p><-LAP-></p></dd>\
			<dd class="start"><p><-START-></p></dd>\
			<dd class="finish"><p><-FINISH-></p></dd>\
			<dd><a href="/<-LOCALE_URL->/gt5/user/<-TARGET_ONLINE_ID->/remoterace/result/d<-RESULT_ID->.html">&nbsp;</a></dd>\
		</dl>\
';

            html = html.replace(/<-INFO_MINUTE->/g, data[i].race_info_minute);
            html = html.replace(/<-COURSE->/g, data[i].course_name);
            html = html.replace(/<-LAP->/g, data[i].lap);
            html = html.replace(/<-START->/g, Date.parseExact(data[i].start_time, 'yyyy/MM/dd HH:mm').format(localize_common_datetime_format));
            html = html.replace(/<-FINISH->/g, Date.parseExact(data[i].end_time, 'yyyy/MM/dd HH:mm').format(localize_common_datetime_format));
            html = html.replace(/<-LOCALE_URL->/g, this.locale_url);
            html = html.replace(/<-TARGET_ONLINE_ID->/g, this.target_online_id);
            html = html.replace(/<-RESULT_ID->/g, data[i].result_id);
        }
        for (j = i; j < 12; j++) {
            html += '\
		<dl class="list nohover">\
			<dd class="course">&nbsp;</dd>\
			<dd class="laps">&nbsp;</dd>\
			<dd class="start">&nbsp;</dd>\
			<dd class="finish">&nbsp;</dd>\
		</dl>\
';
        }
        if (data.length == 0)
            html = '<dl class="blank"><dd class="no_data_logo"><img src="/common/images/gt5/no_data.png" /></dd><dd class="text">' + localize_common_remoterace_no_result_list + '</dd></dl>';

        $('remote_result_list_scroll').innerHTML = html;
        fleXenv.fleXcrollMain("remote_result_list_scroll");
    },
    getResultData: function (result_id, target_online_id) {
        this.job = this.GET_RESULT;
        this.pars = $H({ job: this.job, result_id: result_id, online_id: target_online_id }).toQueryString();
        this.execute();
    },
    updateResultData: function (data) {
        $('remoterace_header_infomation').innerHTML = data[0].course_name + ' / ' + data[0].lap + localize_common_remoterace_laps;
        $('remote_info_starttime').innerHTML = Date.parseExact(data[0].start_time, 'yyyy/MM/dd HH:mm').format(localize_common_datetime_format);
        $('remote_info_endtime').innerHTML = Date.parseExact(data[0].end_time, 'yyyy/MM/dd HH:mm').format(localize_common_datetime_format);
        //		$('remote_info_lap').innerHTML = data[0].lap +'/'+ data[0].lap;

        var html = "";
        for (i = 1; i < data.length; i++) {
            html += '\
<div class="<-OWNER_DATA->">\
<dl class="race_monitor_table body">\
	<dd class="pos"><p><-POSITION-></p></dd>\
	<dd class="driver normal"><p><-DRIVER_NAME-></p></dd>\
	<dd class="user"><p><-USER_ID-></p></dd>\
	<dd class="class"><p><-DRIVER_CLASS-></p></dd>\
	<dd class="car_result"><p><-CAR_NAME-></p></dd>\
	<dd class="time"><p><-TOTAL_TIME-></p></dd>\
	<dd class="besttime"><p id="fastest_key_<-FASTEST_KEY->"><-BEST_TIME-></p></dd>\
	<dd class="updown <-UPDOWN->"><p><-UPDOWN_VALUE-></p></dd>\
</dl>\
</div>\
';
            html = html.replace(/<-POSITION->/g, data[i].result);
            html = html.replace(/<-USER_ID->/g, data[i].user);
            html = html.replace(/<-DRIVER_NAME->/g, data[i].driver);
            html = html.replace(/<-DRIVER_CLASS->/g, data[i].driver_level);
            html = html.replace(/<-CAR_NAME->/g, data[i].car_name.length < 34 ? data[i].car_name : data[i].car_name.substring(0, 33) + "...");
            html = html.replace(/<-TOTAL_TIME->/g, data[i].total.length >= 10 ? "--'--.---" : laptimeFormat(data[i].total, localize_common_laptime_format));
            html = html.replace(/<-BEST_TIME->/g, laptimeFormat(data[i].best, localize_common_laptime_format));
            html = html.replace(/<-FASTEST_KEY->/g, data[i].result);


            if (data[i].user == watcher_online_id)
                html = html.replace(/<-OWNER_DATA->/g, "owner_data");
            else
                html = html.replace(/<-OWNER_DATA->/g, "");

            var updown = data[i].grid - data[i].result;
            if (updown > 0) {
                html = html.replace(/<-UPDOWN->/g, "up");
                html = html.replace(/<-UPDOWN_VALUE->/g, updown);
            }
            else if (updown < 0) {
                html = html.replace(/<-UPDOWN->/g, "down");
                html = html.replace(/<-UPDOWN_VALUE->/g, updown * -1);
            }
            else {
                html = html.replace(/<-UPDOWN->/g, "");
                html = html.replace(/<-UPDOWN_VALUE->/g, "&nbsp;");
            }
        }
        while (i <= 16) {
            html += '<dl class="race_monitor_table body"><dd class="pos">&nbsp;</dd><dd class="user">&nbsp;</dd><dd class="driver">&nbsp;</dd><dd class="class">&nbsp;</dd><dd class="car">&nbsp;</dd><dd class="lastlap">&nbsp;</dd><dd class="lap">&nbsp;</dd><dd class="gap">&nbsp;</dd></dl>';
            i++;
        }
        $('remoterace_result_table').innerHTML = html;
        data.splice(0, 1)
        data.sort(function (a, b) { return a.best - b.best });
        //		$('fastest_key_'+data[0].result).className = "besttime fastest";
        $('fastest_key_' + data[0].result).className = "fastest";
    },

    /* */
    /* Race.vm */
    checkRaceMonitor: function () {
        this.job = this.GET_STATUS;
        this.mode = this.RACE_MONITOR;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    finishRace: function () {
        this.job = this.END_RACE;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
    },

    outputResultMode: function (data) {
        if (data.status != 2 && data.status != 3) {
            clearInterval(timer);
            popup.remoteRaceStartError();
        }
        else if (data.status == 1) {
            alert("Event over");
        }
        else if (data.status == 3) {
            clearInterval(timer);
            this.bspec_monitor_id = 0;
            this.race_timer = setInterval(function () { gt5bspec.getMonitorList(this.bspec_monitor_id); }, 10000);
        }
    },

    getMonitorList: function (bspec_monitor_id) {
        this.job = this.GET_MONITORLIST;
        this.pars = $H({ job: this.job, online_id: target_profile.id, user_number: target_profile.number, bspec_monitor_id: this.bspec_monitor_id }).toQueryString();
        this.execute();
    },

    messageReader: function () {
        if (monitor_message_list.length > 0) {
            $('race_monitor_text_area').innerHTML = monitor_message_list[0] + $('race_monitor_text_area').innerHTML;
            monitor_message_list.shift();
        }
    },

    updateMonitorList: function (data) {
        // Analyze MonitorLog
        var type_check = 0;
        var color = "normal";
        var message_html = "";

        for (var i = 0; i < data.length; i++) {
            if (data[i].type == 1)
                type_check = data[i].bspec_monitor_id;
        }
        for (var i = 0; i < data.length; i++) {
            if (data[i].type == 2) {
                // Event Header
                this.createMonitorView(data[i], data[data.length - 1].local_time);
                $('race_monitor_text_area').innerHTML = '<dd><span class="blue" style="font-weight:bold;">' + data[i].log + '</span></dd>' + $('race_monitor_text_area').innerHTML;
            }
            else if (data[i].type == 1) {
                // Update MonitorTable
                this.updateRaceMonitorTable(data[i].slot_id, data[i].lap_num, data[i].lap_mileage, type_check == data[i].bspec_monitor_id);
            }
            else if (data[i].type == 101 || data[i].type == 201 || data[i].type == 301 || data[i].type == 302) {
                // Monitor Message
                if (data[i].type == 101) color = "blue";
                else if (data[i].type == 201) color = "red";
                else if (data[i].type == 301 || data[i].type == 302) color = "yellow";

                message_html = '<dd><span class="' + color + '">' + localize_common_remoterace_log_lap.replace('%1$s', this.leader_lap) + '</span>' + data[i].value + '</dd>';
                if (this.bspec_monitor_id == 0)
                    $('race_monitor_text_area').innerHTML = message_html + $('race_monitor_text_area').innerHTML;
                else
                    monitor_message_list.push(message_html);
            }
            else if (data[i].type == 401) {
                // Update LastLap Time
                var slot_id_temp = data[i].slot_id - 1;
                this.lastlap_list[slot_id_temp] = data[i].laptime;
            }
            else if (data[i].type == 3) {
                // Finish Race Action
                clearInterval(this.race_timer);
                if (this.total_timer_cleared == false) {
                    clearInterval(this.total_timer);
                    this.total_timer_cleared = true;
                }

                if (this.message_reader_cleard == false) {
                    clearInterval(this.race_message_reader);
                    this.message_reader_cleard = true;
                }

                var local_time = Date.parseExact(data[i].local_time, 'yyyy/MM/dd HH:mm:ss');
                $('race_monitor_text_area').innerHTML = '<dd><span class="blue" style="font-weight:bold;">' + data[i].log + '</span></dd>' + $('race_monitor_text_area').innerHTML;
                $('remote_info_endtime').innerHTML = local_time.format(localize_common_datetime_format);

                if (online_id == target_profile.id) {
                    $('gt5_remote_footer_buttons').innerHTML = '<a href="/' + this.locale_url + '/gt5/user/' + param_online_id + '/remoterace/"><img src="/local/' + this.locale_url + '/images/gt5/remote_race/event.gif" height="40" /></a><a href="/' + this.locale_url + '/gt5/user/' + param_online_id + '/remoterace/result/"><img src="/local/' + this.locale_url + '/images/gt5/remote_race/result.gif" /></a>';
                    var statusCheck = new GT5Bspec(this.locale_url).checkStatusSubWindowUpdate();
                    this.finishRace();
                }
                else { $('remoterace_status_informaition').innerHTML = '&nbsp;'; }
            }
        }
        //		fleXenv.fleXcrollMain("race_monitor_text_area");
        this.bspec_monitor_id = data[i - 1].bspec_monitor_id;
    },

    createMonitorView: function (data, r_local_time) {
        nowLoading(false);
        var user_id_list = data.user_id.split(',');
        var car_list = data.car_name.split(',');
        var driver_list = data.driver_name.split(',');
        var class_list = data.driver_class.split(',');
        var slot_id = "";
        var lap_num = "";
        var lap_mileage = "";
        var recent_local_time = Date.parseExact(r_local_time, 'yyyy/MM/dd HH:mm:ss');
        var start_local_time = Date.parseExact(data.local_time, 'yyyy/MM/dd HH:mm:ss');
        var start_total_time = recent_local_time - start_local_time;
        var start_user_time = new Date();

        this.course_distance = 1000;
        this.race_max_entry = 16;
        this.race_lap = data.lap;
        this.race_distance = this.course_distance * data.lap;
        this.race_grid_data = new Array(user_id_list.length);
        this.lastlap_list = new Array(user_id_list.length);
        this.last_slot_id_list = new Array(user_id_list.length);
        this.total_timer_cleared = false;
        this.message_reader_cleard = false;
        this.fastest_lap = 0;

        for (var i = 0; i < user_id_list.length; i++) {
            this.race_grid_data[i] = { user_id: user_id_list[i], driver_name: driver_list[i], driver_class: class_list[i], car_name: car_list[i] }
            this.lastlap_list[i] = "-'--.---";
            slot_id += (i + 1) + ',';
            lap_num += "1,";
            lap_mileage += "0,";
        }
        this.last_slot_id_list = slot_id.substring(0, slot_id.length - 1).split(',');

        $('remoterace_header_infomation').innerHTML = data.course_name + ' / ' + this.race_lap + localize_common_remoterace_laps;
        $('remote_info_starttime').innerHTML = start_local_time.format(localize_common_datetime_format);
        $('race_monitor_text_area').innerHTML = "";

        this.total_timer = setInterval(function () { totalRaceTimer(start_total_time, start_user_time, localize_common_laptime_format); }, 50);
        this.race_message_reader = setInterval(this.messageReader, 2000);
        this.updateRaceMonitorTable(slot_id.substring(0, slot_id.length - 1), lap_num.substring(0, lap_num.length - 1), lap_mileage.substring(0, lap_mileage.length - 1), true);
    },

    updateRaceMonitorTable: function (slot_id, lap_num, lap_mileage, type_check) {
        var slot_id_list = slot_id.split(',');
        var lap_num_list = lap_num.split(',');
        var mileage_list = lap_mileage.split(',');
        var html = '';
        var slot_index = 0;
        this.leader_lap = parseInt(lap_num_list[0]) < 1 ? this.race_lap : lap_num_list[0];

        if (type_check == true) {
            $('remote_info_lap').innerHTML = this.leader_lap + '/' + this.race_lap;

            html += '\
<dl class="race_monitor_table header">\
	<dd class="pos">' + localize_common_remoterace_position + '</dd>\
	<dd class="driver">' + localize_common_remoterace_drivername + '</dd>\
	<dd class="user">' + localize_common_remoterace_onlineid + '</dd>\
	<dd class="class">' + localize_common_remoterace_class + '</dd>\
	<dd class="car">' + localize_common_remoterace_carname + '</dd>\
	<dd class="lastlap">' + localize_common_remoterace_lastlap + '</dd>\
	<dd class="lap">' + localize_common_remoterace_laps_plural + '</dd>\
	<dd class="gap">' + localize_common_remoterace_gap + '</dd>\
</dl>\
';
            // FastestLap Check
            for (i = 0; i < this.lastlap_list.length; i++) {
                if (this.fastest_lap == 0)
                    this.fastest_lap = this.lastlap_list[i];
                else if (this.fastest_lap > this.lastlap_list[i])
                    this.fastest_lap = this.lastlap_list[i];
            }
            for (i = 0; i < this.race_grid_data.length; i++) {
                slot_index = slot_id_list[i] - 1;
                html += '\
<div class="<-OWNER_DATA->">\
<dl class="race_monitor_table body">\
	<dd class="pos"><p><-POSITION-></p></dd>\
	<dd class="driver <-DRIVER_ICON->"><p><-DRIVER_NAME-></p><div class="updown <-UPDOWN->"><-UPDOWN_VALUE-></div></dd>\
	<dd class="user"><p><-USER_ID-></p></dd>\
	<dd class="class"><p><-DRIVER_CLASS-></p></dd>\
	<dd class="car"><p><-CAR_NAME-></p></dd>\
	<dd class="lastlap"><p<-FASTEST_LAP->><-LAP_TIME-></p></dd>\
	<dd class="lap"><p><-LAP_NUM-></p></dd>\
	<dd class="gap"><-GAP_HTML-></dd>\
	<dd class="lap_distance" style="width:<-LAP_DISTANCE_WIDTH->px;">&nbsp;</dd>\
</dl>\
</div>\
';
                html = html.replace(/<-POSITION->/g, i + 1);
                html = html.replace(/<-CAR_NAME->/g, this.race_grid_data[slot_index].car_name.length < 36 ? this.race_grid_data[slot_index].car_name : this.race_grid_data[slot_index].car_name.substring(0, 35) + "...");
                html = html.replace(/<-DRIVER_NAME->/g, this.race_grid_data[slot_index].driver_name);
                html = html.replace(/<-DRIVER_CLASS->/g, this.race_grid_data[slot_index].driver_class);
                html = html.replace(/<-USER_ID->/g, this.race_grid_data[slot_index].user_id);
                html = html.replace(/<-LAP_TIME->/g, this.lastlap_list[slot_index] == "-'--.---" ? this.lastlap_list[slot_index] : laptimeFormat(this.lastlap_list[slot_index], localize_common_laptime_format));

                if (this.lastlap_list[slot_index] != "-'--.---" && this.lastlap_list[slot_index] <= this.fastest_lap)
                    html = html.replace(/<-FASTEST_LAP->/g, ' class="fastest"');
                else
                    html = html.replace(/<-FASTEST_LAP->/g, '');

                if (this.race_grid_data[slot_index].user_id == online_id)
                    html = html.replace(/<-OWNER_DATA->/g, "owner_data");
                else
                    html = html.replace(/<-OWNER_DATA->/g, "");


                //å‰æ›´æ–°ã‹ã‚‰ã®é †ä½å¤‰å‹•ãƒã‚§ãƒƒã‚¯
                var updown_temp = 0;
                for (j = 0; j < this.last_slot_id_list.length; j++) {
                    if (this.last_slot_id_list[j] - 1 == slot_index) {
                        updown_temp = j;
                    }
                }
                var updown = updown_temp - i;
                if (updown > 0) {
                    html = html.replace(/<-UPDOWN->/g, "up");
                    html = html.replace(/<-UPDOWN_VALUE->/g, updown);
                    html = html.replace(/<-DRIVER_ICON->/g, "blue");
                }
                else if (updown < 0) {
                    html = html.replace(/<-UPDOWN->/g, "down");
                    html = html.replace(/<-UPDOWN_VALUE->/g, updown * -1);
                    html = html.replace(/<-DRIVER_ICON->/g, "pink");
                }
                else {
                    html = html.replace(/<-UPDOWN->/g, "");
                    html = html.replace(/<-UPDOWN_VALUE->/g, "&nbsp;");
                    html = html.replace(/<-DRIVER_ICON->/g, "normal");
                }

                //ã‚®ãƒ£ãƒƒãƒ—ã¨Lapã®å‡¦ç†
                if (lap_num_list[i] == -1) //è‡ªåˆ†ã‚´ãƒ¼ãƒ«
                {
                    html = html.replace(/<-GAP_HTML->/g, '<p>' + localize_common_remoterace_racefinish + '</p>');
                }
                else {
                    html = html.replace(/<-GAP_HTML->/g, '<dl class="<-GAP_GAGE_MAX->"><dd class="gap_base">&nbsp;</dd><dd class="gap_gage" style="width:<-GAP_GAGE_WIDTH->px;">&nbsp;</dd><dd class="base_point">&nbsp;</dd><dd class="target_point" style="left:<-GAP_TARGET_LEFT->px;">&nbsp;</dd></dl>');
                }

                var gap = 0;
                var max_gap = 1000;
                if (i == 0) //1ä½
                {
                    html = html.replace(/<-GAP_GAGE_WIDTH->/g, 0);
                    html = html.replace(/<-GAP_TARGET_LEFT->/g, -4);
                }
                else {
                    if (lap_num_list[0] == -1)
                        gap = (this.race_lap - lap_num_list[i]) * this.course_distance + this.course_distance - mileage_list[i];
                    else
                        gap = ((lap_num_list[0] - lap_num_list[i]) * this.course_distance + parseInt(mileage_list[0])) - mileage_list[i];

                    //ç›¸å¯¾Gap
                    //max_gap = ((lap_num_list[0] - lap_num_list[lap_num_list.length-1]) * this.course_distance + parseInt(mileage_list[0])) - mileage_list[lap_num_list.length-1];

                    max_gap = this.course_distance;
                    if (max_gap > this.course_distance) max_gap = this.course_distance;
                    if (gap >= this.course_distance) {
                        gap = this.course_distance;
                        html = html.replace(/<-GAP_GAGE_MAX->/g, "max");
                    }
                    else
                        html = html.replace(/<-GAP_GAGE_MAX->/g, "");
                    html = html.replace(/<-GAP_GAGE_WIDTH->/g, Math.floor(100 * (gap / max_gap)));
                    html = html.replace(/<-GAP_TARGET_LEFT->/g, Math.floor(100 * (gap / max_gap)) - 4);
                }

                //LapUpdate
                if (lap_num_list[i] == -1)
                    html = html.replace(/<-LAP_NUM->/g, this.race_lap);
                else
                    html = html.replace(/<-LAP_NUM->/g, lap_num_list[i]);

                //LapDistance
                html = html.replace(/<-LAP_DISTANCE_WIDTH->/g, Math.floor(784 * (mileage_list[i] / 1000)));

                //å‘¨å›žé…ã‚Œã®ã¿è¡¨ç¤º
                //html = html.replace(/<-LAP_NUM->/g, parseInt(gap / this.course_distance) != 0 ? "+"+parseInt(gap / this.course_distance) : "-");

            }
            while (i < this.race_max_entry) {
                html += '<dl class="race_monitor_table body"><dd class="pos">&nbsp;</dd><dd class="user">&nbsp;</dd><dd class="driver">&nbsp;</dd><dd class="class">&nbsp;</dd><dd class="car">&nbsp;</dd><dd class="lap">&nbsp;</dd><dd class="gap">&nbsp;</dd></dl>';
                i++;
            }
            this.last_slot_id_list = slot_id_list;
            $('gt5bspec_race_info').innerHTML = html;
        }
    },


    /* */
    /* entry_list.vm */
    openMatchngFriendList: function () {
        $('remote_friend_list_wrapper').style.display = "block";
        fleXenv.fleXcrollMain("remoterace_friend_list");
    },

    closeMatchngFriendList: function () {
        $('remote_friend_list_wrapper').style.display = "none";
    },

    goRace: function () {
        nowLoading(true);
        var save_replay = 0;
        if ($('remote_race_save_replay_flag').checked)
            save_replay = 1;

        this.job = this.GO_RACE;
        this.pars = $H({ job: this.job, replay_save: save_replay }).toQueryString();
        this.execute();
    },

    updateGoRace: function (data) {
        location.href = '/' + this.locale_url + '/gt5/user/' + online_id + '/remoterace/';
    },

    cancelEntry: function () {
        nowLoading(true);
        this.job = this.RESET;
        this.pars = $H({ job: this.job }).toQueryString();
        this.execute();
        location.href = '/' + this.locale_url + '/gt5/user/' + online_id + '/remoterace/';
    },

    removeEntry: function (online_id, driver_id) {
        popup.closePopup();
        nowLoading(true);
        this.job = this.REMOVE_ENTRY;
        this.pars = $H({ job: this.job, driver_id: driver_id }).toQueryString();
        this.remove_online_id = online_id;
        this.remove_driver_id = driver_id;
        this.add_driver_data = "";
        this.execute();
    },

    replaceEntry: function (online_id, delete_driver_id, add_driver_data) {
        this.job = this.REMOVE_ENTRY;
        this.pars = $H({ job: this.job, driver_id: delete_driver_id }).toQueryString();
        this.remove_online_id = online_id;
        this.remove_driver_id = delete_driver_id;
        this.add_driver_data = add_driver_data;
        this.execute();
    },

    updateRemoveEntry: function () {
        if (this.add_driver_data != "") {
            var rp = new GT5Bspec(this.locale_url).setEntry(this.remove_online_id, this.add_driver_data.driver_name, this.add_driver_data.driver_id, this.add_driver_data.driver_level, 1);
        }
        else {
            if (this.remove_online_id == online_id)
                entry_board.entry_board[0] = { online_id: this.remove_online_id, driver_id: "", driver_name: "" };
            else {
                for (i = 1; i < entry_board.entry_board.length; i++) {
                    if (this.remove_driver_id == entry_board.entry_board[i].driver_id)
                        entry_board.entry_board.splice(i, 1);
                }
            }
            entry_board.updateTable();
        }
        nowLoading(false);
    },

    getCarListForMatching: function (online_id) {
        this.job = this.GET_CARLIST;
        this.pars = $H({ job: this.job, online_id: online_id }).toQueryString();
        this.execute();
    },
    updateCarListForMatching: function (data) {
        $('gt5bspec_matching_car_list').innerHTML = this.getCarListHtmlForMatching(data);
        car_data_list = data;
        this.matching_index_car = 99;
        for (i = 0; i < data.length; i++) {
            if (data[i].status == 1) {
                this.matching_index_car = i;
                break;
            }
        }
        $('matching_carlist_' + this.matching_index_car).className = 'selected';
    },

    getDriverList: function () {
        this.job = this.GET_DRIVERLIST;
        this.mode = this.EVENT_SELECT;
        this.pars = $H({ job: this.job, online_id: online_id }).toQueryString();
        this.execute();
    },

    updateDriverList: function (data) {
        $('gt5bspec_driver_list').innerHTML = this.getDriverListHtml(data);
    },

    checkOnlineDriver: function (online_id) {
        this.online_id = online_id;
        this.job = this.GET_DRIVERLIST;
        this.mode = this.CHECK;
        this.pars = $H({ job: this.job, online_id: this.online_id }).toQueryString();
        this.execute();
    },

    checkOnlineDriverResult: function (data) {
        for (i = 0; i < friend_data_list.length; i++) {
            if (friend_data_list[i].id == this.online_id) {
                friend_data_list[i].online_drivers = data;
                check_counter += 1;
                if (friend_data_list[i].online_drivers.length == 0 || data[0].error == 3) {
                    $('friend_list_id_' + friend_data_list[i].id).style.display = "block";
                    $('remote_friend_list_link_' + friend_data_list[i].id).onclick = function (e) { popup.driverNotFound() };
                }
                break;
            }
        }
        if (check_counter == friend_data_list.length) {

        }
    },

    driverSelector: function (number, user_id) {
        this.matching_index_driver = number;

        if (online_id == user_id) {
            for (i = 0; i < 6; i++) {
                if ($('selector_' + i))
                    $('selector_' + i).className = 'selector';
            }
        }
        if ($('selector_' + number).className == "selector")
            $('selector_' + number).className = 'selector selected';
        else
            $('selector_' + number).className = 'selector';

        for (i = 0; i < driver_data_list.length; i++) {
            if ($('selector_' + i).className == "selector selected") {
                $('button_canceler_remote_entry_on').style.backgroundPosition = "0 0";
                $('button_canceler_remote_entry_on').innerHTML = '<a href="javascript:void(0);" onclick="gt5bspec.preEntry(\'' + user_id + '\');" >&nbsp;</a>';
                return;
            }
        }
        $('button_canceler_remote_entry_on').style.backgroundPosition = "0 -28px";
        $('button_canceler_remote_entry_on').innerHTML = '';
    },

    preEntry: function (add_online_id) {
        if (added_list_size > 0) return;

        this.entryFailedDriverNameList = new Array();
        this.set_driver_data_list = new Array();
        for (i = 0; i < driver_data_list.length; i++) {
            if ($('selector_' + i).className == "selector selected") {
                this.set_driver_data_list.push({ driver_id: driver_data_list[i].driver_id, driver_name: driver_data_list[i].name, driver_level: driver_data_list[i].level });
            }
        }

        if (add_online_id == online_id && entry_board.entry_board[0].driver_name != "") {
            gt5bspec.replaceEntry(online_id, entry_board.entry_board[0].driver_id, this.set_driver_data_list[0]);
        }
        else {
            var driver_entry = new Array(this.set_driver_data_list.length);
            for (i = 0; i < this.set_driver_data_list.length; i++) {
                driver_entry[i] = new GT5Bspec(this.locale_url);
                driver_entry[i].setEntry(add_online_id, this.set_driver_data_list[i].driver_name, this.set_driver_data_list[i].driver_id, this.set_driver_data_list[i].driver_level, this.set_driver_data_list.length);
            }
        }
        nowLoading(true);
        popup.closePopup();
    },

    setEntry: function (online_id, driver_name, driver_id, driver_level, add_list_size) {
        this.job = this.ADD_ENTRY;
        this.pars = $H({ job: this.job, online_id: online_id, driver_id: driver_id }).toQueryString();
        this.entry_online_id = online_id;
        this.entry_driver_id = driver_id;
        this.entry_driver_name = driver_name;
        this.entry_driver_level = driver_level;
        this.add_list_size = add_list_size;
        this.execute();
    },
    updateEntry: function () {
        var is_overlap = false;

        for (i = 0; i < entry_board.entry_board.length; i++) {
            if (entry_board.entry_board[i].driver_id == this.entry_driver_id)
                is_overlap = true;
        }

        if (is_overlap == false) {
            if (online_id == this.entry_online_id)
                entry_board.entry_board[0] = { online_id: this.entry_online_id, driver_id: this.entry_driver_id, driver_name: this.entry_driver_name, driver_level: this.entry_driver_level.toString() };
            else
                entry_board.entry_board.push({ online_id: this.entry_online_id, driver_id: this.entry_driver_id, driver_name: this.entry_driver_name, driver_level: this.entry_driver_level.toString() });
        }

        entry_board.updateTable();
    },

    getDriverListHtml: function (data) {
        var html = '';
        driver_datalist_popup = new Array(data.length);
        for (i = 0; i < data.length; i++) {
            html += '\
<dl>\
	<dd class="driver_helmet"><img id="matching_driverlist_image_<-NUMBER->" src="/common/images/gt5/driver/<-HELMET->.png" width="68" height="38" alt="<-DRIVER_NAME->" /></dd>\
	<dd class="driver_condition"><img src="/common/images/gt5/remote_race/events/condition<-DRIVER_CONDITION->.gif" width="16" height="16" alt="" /></dd>\
	<dd class="driver_name"><-NAME-></dd>\
	<dd class="link"><a href="javascript:void(0);" onclick="popup.openDriverProfile(<-NUMBER->);">&nbsp;</a></dd>\
</dl>';
            html = html.replace(/<-NAME->/g, data[i].name);
            html = html.replace(/<-NUMBER->/g, i);
            html = html.replace(/<-HELMET->/g, data[i].helmet_color);
            html = html.replace(/<-DRIVER_CONDITION->/g, convertCondition(data[i].condition));

            driver_datalist_popup[i] = data[i];
        }
        for (j = i; j < 6; j++)
            html += '<dl><dd>&nbsp;</dd></dl>';

        return html;
    },
    getCarListHtmlForMatching: function (data) {
        var html = '';
        for (i = 0; i < data.length; i++) {
            if (data[i].status == 1)
                html += '<dd id="matching_carlist_<-NUMBER->"><a href="javascript:void(0);" onclick="gt5bspec.carSelector(<-NUMBER->)"><img id="matching_carlist_image_<-NUMBER->" src="<-BASE_URL-><-PHOTO_ID->_0.png" width="100" /></a></dd>';
            else
                html += '<dd id="matching_carlist_<-NUMBER->" class="locked"><img id="matching_carlist_image_<-NUMBER->" src="<-BASE_URL-><-PHOTO_ID->_0.png" width="100" /> !LOCKED!</dd>';

            html = html.replace(/<-BASE_URL->/g, photo_base_url);
            html = html.replace(/<-PHOTO_ID->/g, data[i].thumbnail_photo_id);
            html = html.replace(/<-CAR_NAME->/g, data[i].car_name);
            html = html.replace(/<-CAR_ID->/g, data[i].car_id);
            html = html.replace(/<-NUMBER->/g, i);
        }
        return html;
    },
    carSelector: function (number) {
        this.matching_index_car = number;
        $('gt5bspec_matching_car_list').innerHTML = this.getCarListHtmlForMatching(car_data_list);
        $('matching_carlist_' + number).className = 'selected';
    },

    /* Remote Race DriverList */
    getDriverListForMatching: function (online_id) {
        this.job = this.GET_DRIVERLIST;
        this.mode = this.MATCHING;
        this.pars = $H({ job: this.job, online_id: online_id }).toQueryString();
        this.execute();
    },

    updateDriverListForMatching: function (data) {
        $('gt5bspec_matching_driver_list').innerHTML = this.getDriverListHtmlForMatching(data);
        driver_data_list = data;
        popup.popupHeightCorrection();
    },

    getDriverListHtmlForMatching: function (data) {
        var html = '';
        var is_entryed = false;
        for (i = 0; i < data.length; i++) {
            is_entryed = false;
            for (j = 0; j < entry_board.entry_board.length; j++) {
                if (entry_board.entry_board[j].driver_id == data[i].driver_id) {
                    is_entryed = true;
                    break;
                }
            }
            if (data[i].status == 1 && is_entryed == false) {
                html += '\
	<dl class="active">\
	<dd class="driver_select"><a href="javascript:void(0);" onclick="gt5bspec.driverSelector(<-NUMBER->,\'<-USER_ID->\')">&nbsp;</a></dd>\
				';
            }
            else {
                html += '\
	<dl>\
	<dd class="lock"><img src="/common/images/gt5/remote_race/entry/driver_list/lock.png" widtn="90" height="60" alt="lock" /></dd>\
				';
            }
            html += '\
	<dd class="helmet"><img src="/common/images/gt5/driver/<-HELMET->.png" height="60" alt="<-DRIVER_NAME->" /></dd>\
	<dd class="condition"><img src="/common/images/gt5/remote_race/entry/driver_list/condition<-CONDITION->.png" /></dd>\
	<dd class="driver_name"><-DRIVER_NAME-></dd>\
	<dd class="driver_credit_icon icon_<-CREDIT_ICON->">&nbsp;</dd>\
	<dd class="driver_class" style="background-image:url(/local/' + this.locale_url + '/images/gt5/remote_race/t_class.png);"><-DRIVER_CLASS-></dd>\
	<dd class="exp_bar_frame">&nbsp;</dd>\
	<dd class="exp_bar" style="width:<-BAR_WIDTH->px">&nbsp;</dd>\
	<dd class="selector" id="selector_<-NUMBER->"><img src="/common/images/gt5/remote_race/entry/driver_list/check.png" /></dd>\
	</dl>';

            html = html.replace(/<-NAME->/g, data[i].name);
            html = html.replace(/<-DRIVER_ID->/g, data[i].driver_id);
            html = html.replace(/<-NUMBER->/g, i);
            html = html.replace(/<-HELMET->/g, data[i].helmet_color);
            html = html.replace(/<-DRIVER_NAME->/g, data[i].name);
            html = html.replace(/<-CREDIT_ICON->/g, onlineCreditIconConverter(data[i].online_credit, this.locale_url));
            html = html.replace(/<-DRIVER_CLASS->/g, data[i].level);
            html = html.replace(/<-DRIVER_STATUS->/g, data[i].status);
            html = html.replace(/<-USER_ID->/g, data[i].user_id);
            html = html.replace(/<-CONDITION->/g, convertCondition(data[i].condition));
            html = html.replace(/<-BAR_WIDTH->/g, Math.floor(144 * (data[i].experimental / (data[i].expnextlevel / 100) / 100)));
        }
        for (j = i; j < 6; j++) {
            html += '<dl><dd>&nbsp;</dd></dl>';
        }
        return html;
    },

    /* event_select.vm */
    selectEvent: function (event_article_id) {
        if (check_status.status == 0) {
            popup.openRemoteRaceNotice();
        }
        else {
            nowLoading(true);
            document.gt5bspec_event_select.article_id.value = event_article_id;
            document.gt5bspec_event_select.submit();
        }
    },

    /* For Profile */
    getDriverListForProfile: function (online_id) {
        this.job = this.GET_DRIVERLIST;
        this.mode = this.MYHOME_PROFILE;
        this.pars = $H({ job: this.job, online_id: online_id }).toQueryString();
        this.execute();
    },
    updateDriverListForProfile: function (data) {
        var html = "";
        html += '<dt>' + localize_profile_driverlist + '</dt>'
        for (i = 0; i < data.length; i++) {
            html += '<dd class="no_blank"><-DRIVER_NAME-></dd>';

            html = html.replace(/<-DRIVER_NAME->/g, data[i].name);
        }
        for (; i < 6; i++) {
            html += '<dd>&nbsp;</dd>';
        }
        $('gt5_profile_driver_list').innerHTML = html;
    },

    getCarListForProfile: function (online_id) {
        this.job = this.GET_CARLIST;
        this.mode = this.MYHOME_PROFILE;
        this.pars = $H({ job: this.job, online_id: online_id }).toQueryString();
        this.execute();
    },
    updateCarListForProfile: function (data) {
        var html = "";
        html += '<dt>' + localize_profile_garage + '</dt>'
        for (i = 0; i < data.length; i++) {
            html += '<dd class="no_blank"><img src="<-BASE_URL-><-PHOTO_ID->_0.png" title="<-CARNAME->" width="168"></dd>';

            html = html.replace(/<-BASE_URL->/g, photo_base_url);
            html = html.replace(/<-PHOTO_ID->/g, data[i].thumbnail_photo_id);
            html = html.replace(/<-CARNAME->/g, data[i].car_name);
        }
        for (; i < 6; i++) {
            html += '<dd>&nbsp;</dd>';
        }
        $('gt5_profile_garage_list').innerHTML = html;
    }
});


/*-------------------------------*/
/* RemoteRace ã®ã‚¨ãƒ³ãƒˆãƒªãƒ¼ãƒœãƒ¼ãƒ‰ */
/*-------------------------------*/
var GT5BspecEntryBoard = Class.create();
GT5BspecEntryBoard.prototype =
{
    entry_board: new Array(1),

    initialize: function (online_id, max_entry, locale_url) {
        this.entry_board[0] = { online_id: online_id, driver_id: "", driver_name: "", driver_level: "" };
        this.max_entry = max_entry;
        this.locale_url = locale_url;
    },

    updateTable: function () {
        var entry_count = 0;
        var html = '\
	<div  class="remote_race_entry_table">\
		<dl class="table_header">\
			<dd class="online_id">' + localize_common_remoterace_th_online_id + '<dd>\
			<dd class="driver_name">' + localize_common_remoterace_th_driver + '<dd>\
			<dd class="driver_class">' + localize_common_remoterace_th_class + '<dd>\
		</dl>\
';
        for (i = 0; i < this.entry_board.length; i++) {
            html += '\
		<dl class="list_main active<-FIRST_CLASS->">\
			<dd class="icon"><-ICON-></dd>\
			<dd class="online_id"><p><-ONLINE_ID-></p><dd>\
			<dd class="driver_name"><img src="/common/images/gt5/remote_race/entry/icon04.png" /><p><-DRIVER_NAME-></p><dd>\
			<dd class="driver_class"><p><-DRIVER_CLASS-></p><dd>\
			<dd class="link"><a href="javascript:void(0);" onclick="<-FUNCTION->">&nbsp;</a></dd>\
		</dl>\
';
            if (i == 0) {
                html = html.replace(/<-ICON->/g, '<img src="/common/images/gt5/remote_race/entry/icon01.png" />');
                html = html.replace(/<-FUNCTION->/g, 'popup.openBspecMatching(\'<-ONLINE_ID->\',\'<-LOCALE_URL->\');');
            }
            else {
                html = html.replace(/<-ICON->/g, '<img src="/common/images/gt5/remote_race/entry/icon02.png" />');
                html = html.replace(/<-FUNCTION->/g, 'popup.remoteRaceRemoveEntryCheck(\'<-ONLINE_ID->\', \'<-DRIVER_ID->\')');
                //				html = html.replace(/<-FUNCTION->/g, 'gt5bspec.removeEntry(\'<-ONLINE_ID->\', \'<-DRIVER_ID->\')');
            }
            html = html.replace(/<-DRIVER_NAME->/g, this.entry_board[i].driver_name != "" ? this.entry_board[i].driver_name : "&nbsp;");
            html = html.replace(/<-DRIVER_CLASS->/g, this.entry_board[i].driver_level != "" ? this.entry_board[i].driver_level : "&nbsp;");
            html = html.replace(/<-ONLINE_ID->/g, this.entry_board[i].online_id);
            html = html.replace(/<-DRIVER_ID->/g, this.entry_board[i].driver_id != "" ? this.entry_board[i].driver_id : "");
            html = html.replace(/<-FIRST_CLASS->/g, i == 0 ? " first" : "");
            html = html.replace(/<-LOCALE_URL->/g, this.locale_url);
        }

        entry_count = this.entry_board.length
        if (this.entry_board[0].driver_name == "")
            entry_count -= 1;

        html = html.replace(/<-ENTRY_COUNTER->/g, entry_count + "/" + this.max_entry);

        if (!((entry_count == this.max_entry - 1 && this.entry_board[0].driver_name == "") || entry_count >= this.max_entry))
            html += '<dl class="list_main active"><dd class="icon"><img src="/common/images/gt5/remote_race/entry/icon03.png" /></dd><dd class="link"><a href="javascript:void(0);" onclick="gt5bspec.openMatchngFriendList()">&nbsp;</a></dd></dl>';

        for (j = i + 1; j < 16; j++) {
            html += '<dl class="list_main passive"><dd>&nbsp;</dd></dl>';
        }
        html += '</div>';

        this.checkRaceStart();
        $('gt5_remote_entrylist_counter').innerHTML = '<img src="/common/images/gt5/remote_race/entry/icon_driver.png" width="18" height="15" />' + entry_count + '/' + this.max_entry + '</p>';
        $('gt5bspec_entry_table').innerHTML = html;
    },
    checkRaceStart: function () {
        if (entry_board.entry_board[0].driver_id != "" && entry_board.entry_board[1]) {
            $('go_race').style.backgroundPosition = '0px 0px';
            $('go_race').innerHTML = '<a href="javascript:void(0);" onclick="gt5bspec.goRace();">&nbsp;</a>';
        }
        else {
            $('go_race').style.backgroundPosition = '0px -28px';
            $('go_race').innerHTML = '&nbsp;';
        }
    }
}

/*--------------*/
/* ãƒãƒƒãƒ—ã‚¢ãƒƒãƒ— */
/*--------------*/
var GT5Popup = Class.create();
Object.extend(GT5Popup.prototype, GT5Ajax.prototype);
Object.extend(GT5Popup.prototype,
{
    PROFILE: 0,
    MESSAGE_SEND: 1,
    MYHOME_SETTING: 2,

    popup_width: 0,
    popup_height: 0,
    window_height: 0,
    window_width: 0,
    scroll_top: 0,
    scroll_height: 0,

    locale_url: "",

    contents_title: "",
    contents_body: "",
    contents_buttons: "",

    initialize: function (locale_url) {
        this.locale_url = locale_url;
        var body_node = document.body;
        var popup_base = document.createElement('DIV');
        var popup_bg = document.createElement('DIV');
        popup_base.id = "popup_base";
        popup_bg.id = "popup_bg";
        body_node.appendChild(popup_bg);
        body_node.appendChild(popup_base);
    },
    complete: function (res) {
        if (this.job == this.MYHOME_SETTING) {
            this.updateMyhomeSetting(res.evalJSON());
        }
        else if (this.job == this.PROFILE) {
            this.updateProfile(res.evalJSON());
        }
        else if (this.job == this.MESSAGE_SEND) {
            this.updateDirectMessage(res.evalJSON());
        }
    },
    initData: function () {
        this.window_height = getWindowHeight();
        this.window_width = getWindowWidth();
        this.scroll_top = document.body.scrollTop || document.documentElement.scrollTop;
        this.scroll_height = document.body.scrollHeight || document.documentElement.scrollHeight;

        $('popup_bg').style.height = this.scroll_height > getWindowHeight() ? this.scroll_height : getWindowHeight() + "px";
        this.createPopup();
        $('popup_title').style.width = this.popup_width - 38 + "px";
    },
    createPopup: function () {
        $('popup_bg').style.display = "block";
        $('popup_base').style.display = "block";

        $('popup_base').innerHTML = this.getBasePopupHtml();
        $('popup_base').style.width = this.popup_width + "px";
        $('popup_table').style.height = this.popup_height + "px";
        //		$('popup_wrapper').style.height	= this.popup_height + "px";
        $('popup_base').style.left = this.window_width / 2 - this.popup_width / 2 + "px";

        if (this.window_height / 2 + this.scroll_top - this.popup_height / 2 < 0)
            $('popup_base').style.top = 0
        else
            $('popup_base').style.top = this.window_height / 2 + this.scroll_top - this.popup_height / 2 + "px";
    },

    getBasePopupHtml: function () {
        var html = '\
	<table id="popup_table" cellpadding="0" cellspacing="0">\
	<tr>\
		<td class="top_left">&nbsp;</td>\
		<td class="top_center" id="popup_title">&nbsp;</td>\
		<td class="top_right">&nbsp;</td>\
	</tr>\
	<tr>\
		<td class="middle_left">&nbsp;</td>\
		<td class="middle_center"><div id="popup_contents"><p style="text-align:center;"><img style="margin-top:100px;" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></p></td>\
		<td class="middle_right">&nbsp;</td>\
	</tr>\
	<tr>\
		<td class="bottom_left">&nbsp;</td>\
		<td class="bottom_center" id="popup_buttons">&nbsp;</td>\
		<td class="bottom_right">&nbsp;</td>\
	</tr>\
	</table>\
		';
        return html;
    },

    popupHeightCorrection: function () {
        if (this.window_height / 2 + this.scroll_top - $('popup_table').offsetHeight / 2 < 0)
            $('popup_base').style.top = 0
        else
            $('popup_base').style.top = this.window_height / 2 + this.scroll_top - $('popup_table').offsetHeight / 2 + "px";
    },

    closePopup: function () {
        $('popup_base').innerHTML = "";
        $('popup_base').style.display = "none";
        $('popup_bg').style.display = "none";
    },
    updatePopup: function () {
        $('popup_contents').innerHTML = this.contents_body;
        $('popup_title').innerHTML = this.contents_title;
        $('popup_buttons').innerHTML = this.contents_buttons;
    },

    /* RemoteRace RemoveEntry Check */
    remoteRaceRemoveEntryCheck: function (online_id, driver_id) {
        this.popup_width = 300;
        this.popup_height = 190;
        this.initData();
        $('popup_contents').innerHTML = this.getRemoteRaceRemoveEntryCheck(online_id, driver_id);
        this.updatePopup();
    },

    getRemoteRaceRemoveEntryCheck: function (online_id, driver_id) {
        this.contents_title = '<h3>' + localize_common_dialog + '</h3>';
        this.contents_body = '<p style="text-align:center;margin:20px 0;">' + localize_common_remoterace_query_delete_driver + '</p>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/cancel.png" height="20" alt="cancel" /></a><img id="cancel_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
	<dd><a href="javascript:void(0);" onclick="gt5bspec.removeEntry(\'' + online_id + '\', \'' + driver_id + '\')"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a><img id="update_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
</dl>\
		';
    },

    /* RemoteRace GoRace Failed */
    remoteRaceGoRaceFailed: function () {
        this.popup_width = 400;
        this.popup_height = 200;
        this.initData();
        $('popup_contents').innerHTML = this.getRemoteRaceGoRaceFailedHtml();
        this.updatePopup();
    },

    getRemoteRaceGoRaceFailedHtml: function () {
        this.contents_title = '<h3>' + localize_remoterace_dialog_incomplete + '</h3>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/button/popup/ok.png" /></a></dd>\
</dl>';
        this.contents_body = '<p style="margin:10px 10px;">' + localize_remoterace_error01 + '</p>';
    },

    remoteRaceStartError: function () {
        this.popup_width = 400;
        this.popup_height = 200;
        this.initData();
        $('popup_contents').innerHTML = this.getRemoteRaceStartErrorHtml();
        this.updatePopup();
    },

    getRemoteRaceStartErrorHtml: function () {
        this.contents_title = '<h3>' + localize_remoterace_dialog_incomplete + '</h3>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="gt5bspec.cancelEntry();"><img src="/local/' + this.locale_url + '/images/button/popup/ok.png" /></a></dd>\
</dl>\
		';
        this.contents_body = '<p style="margin:10px 10px;">' + localize_remoterace_error04 + '</p>';
    },

    /* Driver Not Found */
    driverNotFound: function () {
        this.popup_width = 400;
        this.popup_height = 200;
        this.initData();
        $('popup_contents').innerHTML = this.getDriverNotFoundHtml();
        this.updatePopup();
    },

    getDriverNotFoundHtml: function () {
        this.contents_title = '<h3>' + localize_remoterace_dialog_incomplete + '</h3>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/button/popup/ok.png" /></a></dd>\
</dl>';
        this.contents_body = '<p style="text-align:center; margin:30px 0 0 0;">' + localize_common_remoterace_driver_not_found + '</p>';
    },

    /* DriverEntry Failed */
    driverEntryFailed: function (driver_name_list) {
        this.popup_width = 400;
        this.popup_height = 200;
        this.initData();
        $('popup_contents').innerHTML = this.getDriverEntryFailedHtml(driver_name_list);
        this.updatePopup();
        this.popupHeightCorrection();
    },

    getDriverEntryFailedHtml: function (driver_name_list) {
        this.contents_title = '<h3>' + localize_remoterace_dialog_incomplete + '</h3>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/button/popup/ok.png" /></a></dd>\
</dl>';
        this.contents_body = '<dl class="popup_driver_entry_failed"><dt>' + localize_common_remoterace_entry_failed + '</dt>';
        for (i = 0; i < driver_name_list.length; i++) {
            this.contents_body += '<dd>' + driver_name_list[i] + '</dd>';
        }
        this.contents_body += '</dl>';
    },

    /* RemoteRace Notice */
    openRemoteRaceNotice: function () {
        this.popup_width = 350;
        this.popup_height = 240;
        this.initData();
        $('popup_contents').innerHTML = this.getRemoteRaceNoticeHtml();
        this.updatePopup();
    },

    getRemoteRaceNoticeHtml: function () {
        this.contents_title = '';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>';
        this.contents_body = localize_remoterace_description;
    },

    /* RemoteRace CarList */
    openRemoteRaceCarList: function () {
        this.popup_width = 600;
        this.popup_height = 400;
        this.initData();
        this.getRemoteRaceCarListHtml();
        this.updatePopup();
        fleXenv.fleXcrollMain("remote_race_car_list");
    },

    getRemoteRaceCarListHtml: function () {
        this.contents_title = '<h3>' + localize_common_remoterace_car_list + '</h3>';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>';

        this.contents_body = '<dl class="remote_race_car_list" id="remote_race_car_list">';
        for (i = 0; i < carname_list.length; i++) {
            this.contents_body += '<dd>' + carname_list[i] + "</dd>";
        }
        this.contents_body += '</dl>';
    },

    /* GT5 Ranking Detail */
    openRankingDetail: function (data_index) {
        this.popup_width = 444;
        this.popup_height = 356;
        this.initData();
        this.getRankingDetailHtml(data_index);
        this.updatePopup();
    },

    getRankingDetailHtml: function (data_index) {
        this.contents_title = '<h3>' + localize_ranking_popup_titlelabel + '</h3>';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>';

        var body_html = '\
	<h1 class="gt5_ranking_popup"><img src="/common/images/products/gt5p/ranking/flag_<-COUNTRY->.png" class="flag iepngfix" width="18" height="12" alt="<-COUNTRY->" /><-ONLINE_ID-></a></h1>\
	<dl class="gt5_ranking_popup_detail">\
		<dd>- <-HEAD_CERATE_TIME-> : <-CREATE_TIME-></dd>\
		<dd>- <-HEAD_CAR_NAME-> : <-CAR_NAME-></dd>\
		<dd>- <-HEAD_TRANSMISSION-> : <-TRANSMISSION-></dd>\
		<dd>- <-HEAD_FRONT_TIRE-> : <-FRONT_TIRE-></dd>\
		<dd>- <-HEAD_REAR_TIRE-> : <-REAR_TIRE-></dd>\
		<dd>- <-HEAD_TCS-> : <-TCS-></dd>\
		<dd>- <-HEAD_SRF-> : <-PROFESSIONAL-></dd>\
		<dd>- <-HEAD_ASR-> : <-ACTIVE_STEERING-></dd>\
		<dd>- <-HEAD_ASM-> : <-ASM-></dd>\
		<dd>- ABS : <-ABS-></dd>\
		<dd>- <-HEAD_STEERING-> : <-CONTROLLER_TYPE-></dd>\
	</dl>\
		';

        body_html = body_html.replace(/<-HEAD_CERATE_TIME->/g, localize_ranking_popup_datelabel);
        body_html = body_html.replace(/<-HEAD_CAR_NAME->/g, localize_ranking_popup_carlabel);
        body_html = body_html.replace(/<-HEAD_TRANSMISSION->/g, localize_ranking_popup_transmission);
        body_html = body_html.replace(/<-HEAD_FRONT_TIRE->/g, localize_ranking_popup_tirefront);
        body_html = body_html.replace(/<-HEAD_REAR_TIRE->/g, localize_ranking_popup_tirerear);
        body_html = body_html.replace(/<-HEAD_TCS->/g, localize_ranking_popup_tcslevel);
        body_html = body_html.replace(/<-HEAD_SRF->/g, localize_ranking_popup_srf);
        body_html = body_html.replace(/<-HEAD_ASR->/g, localize_ranking_popup_active_steering);
        body_html = body_html.replace(/<-HEAD_ASM->/g, localize_ranking_popup_asm);
        body_html = body_html.replace(/<-HEAD_STEERING->/g, localize_ranking_popup_steer_typeheader);
        body_html = body_html.replace(/<-COUNTRY->/g, gt5_ranking.ranking_detail_data[data_index].country);
        body_html = body_html.replace(/<-ONLINE_ID->/g, gt5_ranking.ranking_detail_data[data_index].online_id);
        body_html = body_html.replace(/<-CAR_NAME->/g, gt5_ranking.ranking_detail_data[data_index].car_name);
        body_html = body_html.replace(/<-CREATE_TIME->/g, gt5_ranking.ranking_detail_data[data_index].local_time);

        var transmission = "";
        if (gt5_ranking.ranking_detail_data[data_index].transmission == 0)
            transmission = localize_ranking_popup_at;
        else
            transmission = localize_ranking_popup_mt;
        body_html = body_html.replace(/<-TRANSMISSION->/g, transmission);

        var f_tire = localize_ranking_tire[gt5_ranking.ranking_detail_data[data_index].front_tire];
        var r_tire = localize_ranking_tire[gt5_ranking.ranking_detail_data[data_index].rear_tire];
        body_html = body_html.replace(/<-FRONT_TIRE->/g, f_tire);
        body_html = body_html.replace(/<-REAR_TIRE->/g, r_tire);

        var tcs = gt5_ranking.ranking_detail_data[data_index].tcs;
        if (gt5_ranking.ranking_detail_data[data_index].tcs == 0)
            tcs = localize_ranking_popup_off;
        body_html = body_html.replace(/<-TCS->/g, tcs);

        var srf = localize_ranking_popup_on;
        if (gt5_ranking.ranking_detail_data[data_index].professional == 1)
            srf = localize_ranking_popup_off;
        body_html = body_html.replace(/<-PROFESSIONAL->/g, srf);

        var active_steer = localize_ranking_popup_off;
        if (gt5_ranking.ranking_detail_data[data_index].active_steering == 1)
            active_steer = localize_ranking_popup_on;
        body_html = body_html.replace(/<-ACTIVE_STEERING->/g, active_steer);

        var asm = localize_ranking_popup_off;
        if (gt5_ranking.ranking_detail_data[data_index].asm == 1)
            asm = localize_ranking_popup_on;
        body_html = body_html.replace(/<-ASM->/g, asm);

        var abs = localize_ranking_popup_off;
        if (gt5_ranking.ranking_detail_data[data_index].abs != 0)
            abs = gt5_ranking.ranking_detail_data[data_index].abs;
        body_html = body_html.replace(/<-ABS->/g, abs);

        var controller = localize_ranking_steering[gt5_ranking.ranking_detail_data[data_index].controller_type];
        body_html = body_html.replace(/<-CONTROLLER_TYPE->/g, controller);

        this.contents_body = body_html;
    },

    /* Driver Profile */
    openDriverProfile: function (data_index) {
        this.popup_width = 708;
        this.popup_height = 350;
        this.initData();
        this.getDriverProfileHtml(data_index);
        this.updatePopup();
        this.updateDriverPopupBar(data_index);
    },
    getDriverProfileHtml: function (data_index) {
        this.contents_title = '<h3>' + localize_dirver_mydriver + '</h3>';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>';

        var body_html = '\
	<dl class="popup_driverinfo_left">\
			<dd class="name"><-DRIVER_NAME-></dd>\
			<dd class="status"><img src="/common/images/gt5/driver/status<-STATUS->.png" width="42" height="42" alt="' + localize_dirver_status + '" /></dd>\
			<dd class="helmet"><img src="/common/images/gt5/driver/<-HELMET->.png" width="192" height="108" alt="<-DRIVER_NAME->" /></dd>\
			<dd class="class_header"><img src="/local/' + this.locale_url + '/images/gt5/header/t_class.png" height="28" alt="' + localize_dirver_class + '" /></dd>\
			<dd class="class_text"><-DRIVER_CLASS-></dd>\
			<dd class="level_var_field">\
				<dl class="level_bar">\
					<dd class="frame">&nbsp;</dd>\
					<dd class="value" id="level_bar_value">&nbsp;</dd>\
				</dl>\
			</dd>\
	</dl>\
	<h4 class="popup_driverinfo_right">' + localize_dirver_status + '</h4>\
	<div class="popup_driverstatus">\
	<dl class="status_bar green">\
		<dt>' + localize_dirver_speed + '</dt>\
		<dd class="frame">&nbsp;</dd>\
		<dd class="value" id="speed_bar_value">&nbsp;</dd>\
	</dl>\
	<dl class="status_bar green">\
		<dt>' + localize_dirver_mental + '</dt>\
		<dd class="frame">&nbsp;</dd>\
		<dd class="value" id="mental_bar_value">&nbsp;</dd>\
	</dl>\
	<dl class="status_bar green">\
		<dt>' + localize_dirver_vital + '</dt>\
		<dd class="frame">&nbsp;</dd>\
		<dd class="value" id="vital_bar_value">&nbsp;</dd>\
	</dl>\
	<dl class="status_bar white">\
		<dt>' + localize_dirver_career + '</dt>\
		<dd class="frame">&nbsp;</dd>\
		<dd class="value" id="career_bar_value">&nbsp;</dd>\
	</dl>\
	<dl class="status_bar character">\
		<dt>' + localize_dirver_character + '</dt>\
		<dd class="frame">\
			<span class="cool">' + localize_dirver_cool + '</span>\
			<span class="hot">' + localize_dirver_hot + '</span>\
			<span class="allow" id="character_bar_value"><img src="/common/images/gt5/driver/pointer.png" width="8" height="12" alt="pointer" /></span>\
		</dd>\
	</dl>\
	<dl class="status_result">\
		<dt>' + localize_dirver_results + '</dt>\
		<dd><-RESULT-></dd>\
	</dl>\
	<dl class="online_credit">\
		<dt>' + localize_dirver_credit + '</dt>\
		<dd class="credit_icon icon_<-CREDIT_ICON->">&nbsp;</dd>\
		<dd class="credit_value">Cr. <-ONLINE_CREDIT-></dd>\
	</dl>\
	</div>\
		';

        body_html = body_html.replace(/<-HELMET->/g, driver_datalist_popup[data_index].helmet_color);
        body_html = body_html.replace(/<-DRIVER_NAME->/g, driver_datalist_popup[data_index].name);
        body_html = body_html.replace(/<-STATUS->/g, convertCondition(driver_datalist_popup[data_index].condition));
        body_html = body_html.replace(/<-DRIVER_CLASS->/g, driver_datalist_popup[data_index].level);
        body_html = body_html.replace(/<-RESULT->/g, localize_dirver_result_format).replace("%1$s", driver_datalist_popup[data_index].win_count).replace("%2$s", driver_datalist_popup[data_index].race_count);
        body_html = body_html.replace(/<-ONLINE_CREDIT->/g, driver_datalist_popup[data_index].online_credit);
        body_html = body_html.replace(/<-CREDIT_ICON->/g, onlineCreditIconConverter(driver_datalist_popup[data_index].online_credit, this.locale_url));

        this.contents_body = body_html;
    },
    updateDriverPopupBar: function (data_index) {
        var max_var_width = 188;

        $('level_bar_value').style.width = Math.floor(max_var_width * (driver_datalist_popup[data_index].experimental / (driver_datalist_popup[data_index].expnextlevel / 100) / 100)) + "px";

        $('speed_bar_value').style.width = Math.floor(max_var_width * (driver_datalist_popup[data_index].speed / 100)) + "px";
        $('mental_bar_value').style.width = Math.floor(max_var_width * (driver_datalist_popup[data_index].mental / 100)) + "px";
        $('vital_bar_value').style.width = Math.floor(max_var_width * (driver_datalist_popup[data_index].physical / 100)) + "px";
        $('career_bar_value').style.width = Math.floor(max_var_width * (driver_datalist_popup[data_index].career / 100)) + "px";
        $('character_bar_value').style.left = Math.floor(max_var_width * (driver_datalist_popup[data_index].heart / 100)) + "px";
    },

    /* Now Writing */
    nowWriting: function (article_id) {
        this.popup_width = 150;
        this.popup_height = 50;
        this.initData();
        $('popup_contents').innerHTML = "<h2>Now writing...</h2>";
    },

    /* GT5 News */
    openGt5News: function (article_id) {
        this.popup_width = 644;
        this.popup_height = 300;
        this.initData();
        this.getGt5NewsHtml(article_id);
        this.updatePopup();
        this.popupHeightCorrection();
    },

    getGt5NewsHtml: function (article_id) {
        this.contents_title = '<h3>' + localize_newspopup_gt5_info + '</h3>';
        this.contents_body = '\
	<dl class="gt5_news_popup_header">\
		<dt><-NEWS_TITLE-></dt>\
		<dd><-NEWS_CREATE_TIME-></dd>\
	</dl>\
	<-IMAGE_INFO->\
	<p class="popup_gt5news"><-NEWS_BODY-></p>\
	';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>';

        this.contents_body = this.contents_body.replace(/<-NEWS_TITLE->/g, eval("gt5_news_data_title_" + article_id));
        this.contents_body = this.contents_body.replace(/<-NEWS_CREATE_TIME->/g, eval("gt5_news_data_create_time_" + article_id));
        this.contents_body = this.contents_body.replace(/<-NEWS_BODY->/g, eval("gt5_news_data_body_" + article_id));
        if (eval("gt5_news_data_img_" + article_id) != '')
            this.contents_body = this.contents_body.replace(/<-IMAGE_INFO->/g, "<img class=\"gt5news\" src=\"/c/binary/images/" + article_id + "/" + eval("gt5_news_data_img_" + article_id) + "\" width=\"180\" />");
        else
            this.contents_body = this.contents_body.replace(/<-IMAGE_INFO->/g, '');
    },

    /* MyHome Setting */
    openMyhomeSetting: function () {
        this.popup_width = 724;
        this.popup_height = 660;
        this.initData();
        this.job = this.MYHOME_SETTING;
        this.request_url = '/' + this.locale_url + '/api/gt5/profile/';
        this.pars = $H({ online_id: online_id }).toQueryString();
        this.execute();
    },

    updateMyhomeSetting: function (data) {
        this.profile_data = data;
        this.getOnlineProfileSettingHtml();
        this.updatePopup();


        var input_target = '[\
	{"input_id" : "myhome_setting_playtime",       "counter_id" : "profile_playtime_limit",       "max_length" : "20"},\
	{"input_id" : "myhome_setting_comment",        "counter_id" : "profile_comment_limit",        "max_length" : "80"},\
	{"input_id" : "myhome_setting_welcomemessage", "counter_id" : "profile_welcomemessage_limit", "max_length" : "30"}\
		]'.evalJSON();
        var button_id = 'update_profile_button';
        var input_checker = new ProfileInputChecker(input_target, button_id);
        Event.observe('myhome_setting_playtime', 'keyup', input_checker.execute.bind(input_checker));
        Event.observe('myhome_setting_comment', 'keyup', input_checker.execute.bind(input_checker));
        Event.observe('myhome_setting_welcomemessage', 'keyup', input_checker.execute.bind(input_checker));
    },

    /* Online Photo */
    openOnlinePhoto: function (index) {
        this.popup_width = 840;
        this.popup_height = 575;
        this.initData();
        $('popup_contents').innerHTML = this.getPhotoHtml(index);
        this.updatePopup();
        this.popupHeightCorrection();

        if (online_id != target_profile.id)
            $('gt5_photo_popup_comment').style.height = $('gt5_photo_popup_comment').offsetHeight + 10 + "px";
        Event.observe('popup_image_wrapper', 'click', function (e) {
            if (document.all)
                dx = event.offsetX;
            else
                dx = e.layerX;

            if (0 <= dx && dx <= 266) {
                if (index > 0)
                    popup.openOnlinePhoto(index - 1);
            }
            else if (267 <= dx && dx <= 534) {
                popup.closePopup();
            }
            else if (535 <= dx && dx <= 800) {
                if (index < photo_data_list.length - 1)
                    popup.openOnlinePhoto(index + 1);
            }

        });

        Event.observe('popup_image_wrapper', 'mousemove', function (e) {
            if (document.all)
                dx = event.offsetX;
            else
                dx = e.layerX;

            if (0 <= dx && dx <= 266) {
                $('gt5_photo_detail_button_cancel').className = "cancel";
                $('gt5_photo_detail_button_next').className = "next";
                if (index == 0) {
                    $('gt5_photo_detail_button_prev').className = "prev";
                    $('popup_image_wrapper').className = "popup_image_wrapper";
                }
                else {
                    $('gt5_photo_detail_button_prev').className = "prev on";
                    $('popup_image_wrapper').className = "popup_image_wrapper pointer";
                }
            }
            else if (267 <= dx && dx <= 534) {
                $('gt5_photo_detail_button_prev').className = "prev";
                $('gt5_photo_detail_button_cancel').className = "cancel on";
                $('gt5_photo_detail_button_next').className = "next";
                $('popup_image_wrapper').className = "popup_image_wrapper pointer";
            }
            else if (535 <= dx && dx <= 800) {
                $('gt5_photo_detail_button_prev').className = "prev";
                $('gt5_photo_detail_button_cancel').className = "cancel";
                if (index >= photo_data_list.length - 1) {
                    $('gt5_photo_detail_button_next').className = "next";
                    $('popup_image_wrapper').className = "popup_image_wrapper";
                }
                else {
                    $('gt5_photo_detail_button_next').className = "next on";
                    $('popup_image_wrapper').className = "popup_image_wrapper pointer";
                }
            }
            //			$('photo_debug').innerHTML = "debug : " + dx + " : " + dy + " : " + index + " : " + photo_data_list.length;
        });

        Event.observe('popup_image_wrapper', 'mouseover', function (e) { this.getPhotoMouseOverObject(); } .bind(this));
        Event.observe('popup_image_wrapper', 'mouseout', function (e) {
            $('photo_detail_button').style.display = "none";
            $('photo_detail').style.display = "none"
        });
    },

    getPhotoMouseOverObject: function () {
        $('photo_detail_button').style.display = "block";
        $('photo_detail').style.display = "block";
    },

    /* Online Course */
    openOnlineCourse: function (index) {
        this.popup_width = 708;
        this.popup_height = 425;
        this.initData();
        $('popup_contents').innerHTML = this.getCourseHtml(index);
        this.updatePopup();
    },

    /* Direct Message */
    openDirectMessage: function (online_id, select_switch, reply_subject_id) // select_switch:true ã§å®›å…ˆãƒ—ãƒ«ãƒ€ã‚¦ãƒ³ã€select_switch:false ã§å®›å…ˆå›ºå®š
    {
        if (service_write_mail != 0) {
            alert(localize_gtcom_cannot_write);
        }
        else {
            this.popup_width = 454;
            this.popup_height = 410;
            this.initData();
            this.getDirectMessageHtml(online_id, select_switch);
            this.updatePopup();

            //			$('submit_mail_button').style.display = "inline";

            if (online_id != null) {
                this.displayAvatorForMailPopup(online_id);
            }
            else {
                this.displayAvatorForMailPopup($('send_message_to').value);
                Event.observe('send_message_to', 'change', function (e) {
                    this.displayAvatorForMailPopup($('send_message_to').value);
                } .bind(this));
            }

            if (reply_subject_id) {
                eval("$('send_message_subject').value = localize_format_mail_reply_format.replace('%1$s', mail_subject_" + reply_subject_id + ");");
                $('send_message_subject').value = $('send_message_subject').value.replace(/&#36;/g, '$').replace(/&#39;/g, '\'').replace(/&quot;/g, '"').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
            }
            var input_target = '[\
	{"input_id" : "send_message_subject", "counter_id" : "popup_mailsend_counter_subject", "max_length" : "40"},\
	{"input_id" : "send_message_body",    "counter_id" : "popup_mailsend_counter_body",    "max_length" : "250"}\
			]'.evalJSON();
            var button_id = 'submit_mail_button';
            var input_checker = new MailInputChecker(input_target, button_id);
            Event.observe('send_message_subject', 'keyup', input_checker.execute.bind(input_checker));
            Event.observe('send_message_body', 'keyup', input_checker.execute.bind(input_checker));
        }
    },

    displayAvatorForMailPopup: function (online_id) {
        var id_match = false;
        for (i = 0; i < friend_data_list.length; i++) {
            if (online_id == friend_data_list[i].id) {
                id_match = true;
                break;
            }
        }
        if (id_match == false)
            return;

        html = '\
<dl class="popup_userprofile_avatar">\
	<dd class="avatar_bg color_' + friend_data_list[i].menu_color + '">&nbsp;</dd>\
	<dd class="avatar"><-AVATAR-></dd>\
</dl>\
		';
        if (friend_data_list[i].photo_avatar != "")
            html = html.replace(/<-AVATAR->/g, '<img src="' + photo_base_url + friend_data_list[i].photo_avatar + '_0.jpg" width="48" height="48" />');
        else
            html = html.replace(/<-AVATAR->/g, '');
        $('gt5_popup_mail_avator').innerHTML = html;
    },

    /* User Profile */
    openProfile: function (online_id) {
        this.popup_width = 454;
        this.popup_height = 410;
        this.initData();
        this.job = this.PROFILE;
        this.request_url = '/' + this.locale_url + '/api/gt5/profile/';
        this.pars = $H({ online_id: online_id }).toQueryString();
        this.execute();
    },
    updateProfile: function (data) {
        //		var message_send = 
        this.getProfileDetail(data);
        this.updatePopup();
    },

    /* RemoteRace DriverSelect */
    openBspecMatching: function (online_id, locale_url) {
        this.popup_width = 273;
        this.popup_height = 593;
        this.initData();
        $('popup_base').innerHTML = this.getBaseRemoteDriverPopupHtml();

        gt5bspec.matching_index_driver = 0;
        gt5bspec.matching_index_car = 0;

        this.getBspecMatchingHtml(online_id);
        this.updatePopup();

        //		new GT5Profile(online_id, locale_url).getDriverListForMatching ();
        new GT5Bspec(locale_url).getDriverListForMatching(online_id);
    },

    getBaseRemoteDriverPopupHtml: function () {
        var html = '\
<div class="remote_drivers_popup">\
	<h3 id="popup_title" class="popup_title">&nbsp;</h3>\
	<div id="popup_contents" class="popup_contents">&nbsp;</div>\
	<div id="popup_buttons" class="popup_buttons">&nbsp;</div>\
</div>\
	';
        return html;
    },

    getBspecMatchingHtml: function (online_id) {
        this.contents_title = online_id;
        this.contents_body = '\
<div class="gt5bspec_matching_driver_list" id="gt5bspec_matching_driver_list">\
	<dl><dd>&nbsp;</dd></dl>\
	<dl><dd>&nbsp;</dd></dl>\
	<dl><dd style="text-align:center;"><img style="margin-top:30px;" src="/common/images/gt5/loading.gif" width="16" height="16" alt="loading" /></dd></dl>\
	<dl><dd>&nbsp;</dd></dl>\
	<dl><dd>&nbsp;</dd></dl>\
	<dl><dd>&nbsp;</dd></dl>\
</div>\
		';

        this.contents_buttons = '\
<dl class="gt5bspec_matching_bottom">\
	<dd class="entry_cancel"><a href="javascript:void(0);" onclick="popup.closePopup();" ><img src="/local/' + this.locale_url + '/images/gt5/remote_race/cancel02.png" width="107" height="28" /></a></dd>\
	<dd class="entry_ok" id="button_canceler_remote_entry_on" style="background:url(/local/' + this.locale_url + '/images/gt5/remote_race/ok.png) no-repeat 0 -28px;"></dd>\
</dl>\
';
        //	<dd class="button_canceler" id="button_canceler_remote_entry_on"><img src="/common/images/button/popup/off.png" width="92" height="20" /></dd>\
        //		this.contents_buttons = this.contents_buttons.replace(/<-ONLINE_ID->/g, online_id);
    },

    /* Normal Error */
    openNormalError: function () {
        this.popup_width = 400;
        this.popup_height = 250;
        this.initData();
        $('popup_contents').innerHTML = this.getNormalErrorHtml();
        this.updatePopup();
    },
    getNormalErrorHtml: function () {
        this.contents_title = '<h3>' + localize_common_dialog + '</h3>';
        this.contents_body = '<p style="text-align:center;margin:20px 0;">' + localize_gtcom_error_normal + '</p>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a></dd>';
    },

    /* Delete Check */
    openDeleteCheck: function (comment_id, category) {
        this.popup_width = 300;
        this.popup_height = 190;
        this.initData();
        $('popup_contents').innerHTML = this.getBbsDeleteCheckHtml(comment_id, category);
        this.updatePopup();
    },

    getBbsDeleteCheckHtml: function (target_id, category) {
        this.contents_title = '<h3>' + localize_common_dialog + '</h3>';
        this.contents_body = '<p style="text-align:center;margin:20px 0;">' + localize_bbs_delete_dialog_text.replace("<br /><br />", "<br />") + '</p>';
        this.contents_buttons = '\
<dl class="popup_buttons">\
	<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/cancel.png" height="20" alt="cancel" /></a><img id="cancel_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>';

        if (category == "bbs")
            this.contents_buttons += '<dd><a href="javascript:void(0);" onclick="gt5contents.deleteBbsData(' + target_id + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a><img id="update_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd></dl>';
        else if (category == "receive_mail")
            this.contents_buttons += '<dd><a href="javascript:void(0);" onclick="gt5mail.deleteMessage(' + target_id + ',\'receive\');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a><img id="update_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd></dl>';
        else if (category == "send_mail")
            this.contents_buttons += '<dd><a href="javascript:void(0);" onclick="gt5mail.deleteMessage(' + target_id + ',\'send\');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a><img id="update_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd></dl>';
    },
    /* --- */
    /*------------------------*/
    /* ãƒãƒƒãƒ—ã‚¢ãƒƒãƒ—ã®htmlæç”» */
    /*------------------------*/
    getOnlineProfileSettingHtml: function () {
        this.contents_title = "<h3>" + localize_profile_setting + "</h3>";
        var html = "";
        html = '\
		<form name="profile_form">\
		<dl class="profile_header">\
			<dt>' + localize_profile_basic_infomation + '</dt>\
			<dd>' + localize_profile_description.replace(/<br \/><br \/>/g, "<br />") + '</dd>\
		</dl>\
		<dl class="profile_online_id">\
			<dt>' + localize_profile_online_id + '</dt>\
			<dd class="online_id profile_setting"><p><span class="flag <-COUNTRY->">&nbsp;</span><-ONLINE_ID-></p></dd>\
			<dd class="open_states">' + localize_profile_open_to_all + '</dd>\
		</dl>\
		<dl class="profile_ingame_friend">\
			<dt>' + localize_profile_friend_count + '</dt>\
			<dd><-FRIEND-></dd>\
			<dd class="open_states">' + localize_profile_open_to_all + '</dd>\
		</dl>\
		<dl class="profile_playtime">\
			<dt>' + localize_profile_play_time + '&nbsp;<span id="profile_playtime_limit">' + localize_profile_within_n_letters.replace("%1$s", "20") + '</span></dt>\
			<dd class="radiobutton">\
				<input type="radio" name="playtime_level" value="0"<-PLAYTIME_CHECKED1-> />&nbsp;' + localize_profile_open_to_all + '&nbsp;&nbsp;&nbsp;\
				<input type="radio" name="playtime_level" value="1"<-PLAYTIME_CHECKED2-> />&nbsp;' + localize_profile_open_to_friend + '\
			</dd>\
			<dd><textarea  id="myhome_setting_playtime"><-PLAYTIME-></textarea></dd>\
		</dl>\
		<dl class="profile_profilecomment">\
			<dt>' + localize_profile_introduce + '&nbsp;<span id="profile_comment_limit">' + localize_profile_within_n_letters.replace("%1$s", "80") + '</span></dt>\
			<dd class="radiobutton">\
				<input type="radio" name="comment_level" value="0"<-COMMENT_CHECKED1-> />&nbsp;' + localize_profile_open_to_all + '&nbsp;&nbsp;&nbsp;\
				<input type="radio" name="comment_level" value="1"<-COMMENT_CHECKED2-> />&nbsp;' + localize_profile_open_to_friend + '\
			</dd>\
			<dd><textarea id="myhome_setting_comment"><-COMMENT-></textarea></dd>\
		</dl>\
		<div class="break">&nbsp;</div>\
		<dl class="profile_welcomemessage">\
			<dt>' + localize_profile_welcomemessage + '&nbsp;<span id="profile_welcomemessage_limit">' + localize_profile_within_n_letters.replace("%1$s", "30") + '</span></dt>\
			<dd><input type="text" id="myhome_setting_welcomemessage" value="<-WELCOMEMESSAGE->" /></dd>\
		</dl>\
		<dl class="profile_button_header">\
			<dt>' + localize_profile_button_display_setting + '</dt>\
			<dd>' + localize_profile_button_display_description.replace(/<br \/><br \/>/g, "<br />") + '</dd>\
		</dl>\
		<dl class="profile_button_level">\
			<dt>' + localize_profile_button_display + '</dt>\
			<dd class="radiobutton">\
				<input type="radio" name="profile_button_level" value="0"<-PROFILE_CHECKED1-> />&nbsp;' + localize_profile_open_to_all + '&nbsp;&nbsp;&nbsp;\
				<input type="radio" name="profile_button_level" value="1"<-PROFILE_CHECKED2-> />&nbsp;' + localize_profile_open_to_friend + '\
			</dd>\
		</dl>\
		</form>\
		';

        //			<dd><input type="text" class="text" id="myhome_setting_playtime" value="<-PLAYTIME->" /></dd>\
        html = html.replace(/<-ONLINE_ID->/g, this.profile_data.id);
        html = html.replace(/<-COUNTRY->/g, this.profile_data.country);
        html = html.replace(/<-PLAYTIME->/g, this.profile_data.playtime.replace(/\$/g, '&#36;'));
        html = html.replace(/<-COMMENT->/g, this.profile_data.comment.replace(/\$/g, '&#36;'));
        html = html.replace(/<-WELCOMEMESSAGE->/g, this.profile_data.welcomemessage.replace(/\$/g, '&#36;'));
        html = html.replace(/<-FRIEND->/g, this.profile_data.friend_count);

        if (this.profile_data.playtime_level == 0) {
            html = html.replace(/<-PLAYTIME_CHECKED1->/g, " checked");
            html = html.replace(/<-PLAYTIME_CHECKED2->/g, "");
        }
        else {
            html = html.replace(/<-PLAYTIME_CHECKED1->/g, "");
            html = html.replace(/<-PLAYTIME_CHECKED2->/g, " checked");
        }
        if (this.profile_data.comment_level == 0) {
            html = html.replace(/<-COMMENT_CHECKED1->/g, " checked");
            html = html.replace(/<-COMMENT_CHECKED2->/g, "");
        }
        else {
            html = html.replace(/<-COMMENT_CHECKED1->/g, "");
            html = html.replace(/<-COMMENT_CHECKED2->/g, " checked");
        }
        if (this.profile_data.profile_level == 0) {
            html = html.replace(/<-PROFILE_CHECKED1->/g, " checked");
            html = html.replace(/<-PROFILE_CHECKED2->/g, "");
        }
        else {
            html = html.replace(/<-PROFILE_CHECKED1->/g, "");
            html = html.replace(/<-PROFILE_CHECKED2->/g, " checked");
        }
        this.contents_body = html;
        this.contents_buttons = '\
		<dl class="popup_buttons">\
			<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/cancel.png" height="20" alt="' + localize_common_cancel + '" /></a><img id="cancel_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
			<dd><a href="javascript:void(0);" onclick="gt5profile.postProfile();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/ok.png" height="20" alt="' + localize_common_ok + '" /></a><img id="update_profile_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
		</dl>\
		';
    },


    getPhotoHtml: function (index) {
        this.contents_title = '<h3>' + localize_mode_photo + '</h3>';
        var html = '\
	<dl id="gt5_photo_popup" class="gt5_photo_popup">\
		<dd class="popup_image"><img src="<-BASE_URL-><-PHOTO_ID->_0.jpg" height="450" /></dd>\
	</dl>\
	<dl class="photo_detail" id="photo_detail">\
		<dd class="date">' + localize_photo_update_date + '&nbsp;<span><-SHOT_TIME-></span></dd>\
		<dd class="place">' + localize_photo_detail_shooting_place + '<span><-PHOTO_PLACE-></span></dd>\
	</dl>\
	<dl class="photo_detail_button" id="photo_detail_button">\
		<dd class="prev" id="gt5_photo_detail_button_prev">&nbsp;</dd>\
		<dd class="cancel" id="gt5_photo_detail_button_cancel">&nbsp;</dd>\
		<dd class="next" id="gt5_photo_detail_button_next">&nbsp;</dd>\
	</dl>\
	<div class="popup_image_wrapper" id="popup_image_wrapper">&nbsp;</div>\
	<dl id="gt5_photo_popup_comment" class="gt5_photo_popup_comment<-EXTENSION_CLASS->">\
		<dd><pre><-COMMENT-></pre></dd>\
		<-COMMENT_EDIT_BUTTON->\
	</dl>\
			';

        this.contents_buttons = '\
	<dl class="popup_buttons">\
		<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>\
		';

        if (online_id == target_profile.id) {
            html = html.replace(/<-COMMENT_EDIT_BUTTON->/g, '<dd class="popup_button"><a href="<-BASE_URL-><-PHOTO_ID->_0.jpg" target="blank"><img src="/common/images/gt5/popup/photo/bt_file.png"></a>&nbsp;<a href="javascript:void(0);" onclick="popup.gt5PhotoEdit(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_comment.png" alt="' + localize_couse_comment_edit + '" /></a></dd>');
            html = html.replace(/<-EXTENSION_CLASS->/g, '');
        }
        else {
            html = html.replace(/<-COMMENT_EDIT_BUTTON->/g, '<dd class="popup_button"><a href="<-BASE_URL-><-PHOTO_ID->_0.jpg" target="blank"><img src="/common/images/gt5/popup/photo/bt_file.png"></a></dd>');
            html = html.replace(/<-EXTENSION_CLASS->/g, ' friend_photo');
        }

        html = html.replace(/<-BASE_URL->/g, photo_base_url);
        html = html.replace(/<-PHOTO_ID->/g, photo_data_list[index].photo_id);
        html = html.replace(/<-COMMENT->/g, photo_data_list[index].comment.replace(/\$/g, '&#36;').replace(/\s/g, '&nbsp;'));

        var create_time = Date.parseExact(photo_data_list[index].local_time, 'yyyy/MM/dd HH:mm:ss');
        html = html.replace(/<-SHOT_TIME->/g, create_time.format(localize_common_datetime_format));
        html = html.replace(/<-PHOTO_PLACE->/g, photo_data_list[index].place);

        this.contents_body = html;
    },

    gt5PhotoEdit: function (index) {
        if (service_write_photo != 0) {
            alert(localize_gtcom_cannot_write);
        }
        else {
            $('gt5_photo_popup_comment').innerHTML = '\
			<dd><textarea name="photo_comment" id="photo_comment">' + photo_data_list[index].comment.replace(/\n/g, ' ') + '</textarea></dd>\
			<dd class="popup_text_counter"><p id="popup_text_counter_photo"></p></dd>\
			<dd id="popup_photo_edit_button" class="popup_button">\
				<a href="javascript:void(0);" onclick="popup.gt5PhotoEditCancel(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_cancel.png" alt="' + localize_common_cancel + '" /></a>\
				<a href="javascript:void(0);" onclick="gt5photo.editComment(\'' + photo_data_list[index].photo_id + '\')"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_ok.png" alt="' + localize_common_ok + '" /></a>\
			</dd>\
			<dd class="popup_button"><img id="popup_button_off_cancel" src="/local/' + this.locale_url + '/images/gt5/buttons/sq_off.png" /><img id="popup_button_off_ok" src="/local/' + this.locale_url + '/images/gt5/buttons/sq_off.png" /></dd>\
			';
            var text_counter = new TextCounter("photo_comment", "popup_text_counter_photo", "popup_button_off_ok", 140);
            Event.observe('photo_comment', 'keyup', text_counter.execute.bind(text_counter));
        }
    },

    gt5PhotoEditCancel: function (index) {
        $('gt5_photo_popup_comment').innerHTML = '\
		<dd><pre>' + photo_data_list[index].comment.replace(/\n/g, ' ') + '</pre></dd>\
		<dd class="popup_button"><a href="<-BASE_URL-><-PHOTO_ID->_0.jpg" target="blank"><img src="/common/images/gt5/popup/photo/bt_file.png"></a>&nbsp;<a href="javascript:void(0);" onclick="popup.gt5PhotoEdit(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_comment.png" alt="' + localize_couse_comment_edit + '" /></a></dd>\
		';
    },

    getCourseHtml: function (index) {
        this.contents_title = '<h3>' + localize_mode_course + '</h3>';
        var html = '\
	<dl id="gt5_course_popup" class="gt5_course_popup">\
		<dt><img src="/common/images/gt5/course/<-COURSE_GENRE_PHOTO->" width="220" height="111" /></dt>\
		<dd class="course_image"><img src="<-BASE_URL-><-COURSE_PHOTO_ID->_0.png" height="108" /><img class="clock" src="/common/images/gt5/course/icon_clock.png" width="32" height="32" alt="clock" /><img class="weather" src="/common/images/gt5/course/icon_weather_<-COURSE_WEATHER->.png" width="32" height="32" alt="weather" /></dd>\
	</dl>\
	<div class="gt5_course_popup_data">\
		<dl class="gt5_course_popup_header">\
			<dt><-COURSE_GENRE-></dt>\
			<dd class="title"><-COURSE_TITLE-></dd>\
			<dd class="length"><-COURSE_LENGTH-></dd>\
			<dd class="create_time"><-CREATE_TIME-></dd>\
		</dl>\
		<dl id="gt5_course_popup_comment" class="gt5_course_popup_comment">\
			<dd><pre><-COMMENT-></pre></dd>\
			<-COURSE_COMMENT_EDIT->\
		</dl>\
		<dl class="gt5_course_popup_info">\
			<dd><-COURSE_STRAIGHT-></dd>\
			<dd><-COURSE_ELEVATION-></dd>\
			<dd><-COURSE_CORNER-></dd>\
		</dl>\
	</div>\
		';

        this.contents_buttons = '\
	<dl class="popup_buttons">\
		<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
	</dl>\
		';

        if (online_id == target_profile.id)
            html = html.replace(/<-COURSE_COMMENT_EDIT->/g, '<dd class="popup_button"><a href="javascript:void(0);" onclick="popup.gt5CourseEdit(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_comment.png" alt="' + localize_couse_comment_edit + '" /></a></dd>');
        else
            html = html.replace(/<-COURSE_COMMENT_EDIT->/g, '');

        if (course_data_list[index].genre_hash == gt5course.TOSCANA)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme01.jpg");
        else if (course_data_list[index].genre_hash == gt5course.EIFEL_CIRCUIT)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme02.jpg");
        else if (course_data_list[index].genre_hash == gt5course.ASO)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme03.jpg");
        else if (course_data_list[index].genre_hash == gt5course.LIEGE)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme04.jpg");
        else if (course_data_list[index].genre_hash == gt5course.ALASKA)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme05.jpg");
        else if (course_data_list[index].genre_hash == gt5course.EIFEL_KART)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme06.jpg");
        else if (course_data_list[index].genre_hash == gt5course.TOKYO)
            html = html.replace(/<-COURSE_GENRE_PHOTO->/g, "theme07.jpg");

        html = html.replace(/<-BASE_URL->/g, photo_base_url);
        html = html.replace(/<-COURSE_PHOTO_ID->/g, course_data_list[index].thumbnail_photo_id);
        html = html.replace(/<-COURSE_WEATHER->/g, course_data_list[index].weather);

        html = html.replace(/<-COURSE_GENRE->/g, course_data_list[index].genre);
        html = html.replace(/<-COURSE_TITLE->/g, course_data_list[index].title);
        html = html.replace(/<-COURSE_LENGTH->/g, localize_common_format_value.replace('%1$s', localize_couse_length).replace('%2$s', course_data_list[index].length));

        //		var create_time = Date.parseExact(course_data_list[index].create_time, 'yyyy-MM-ddTHH:mm:ssZ');
        var create_time = Date.parseExact(course_data_list[index].local_time, 'yyyy/MM/dd HH:mm:ss');
        html = html.replace(/<-CREATE_TIME->/g, create_time.format(localize_common_datetime_format));

        html = html.replace(/<-COMMENT->/g, course_data_list[index].comment.replace(/\$/g, '&#36;').replace(/\s/g, '&nbsp;'));

        html = html.replace(/<-COURSE_STRAIGHT->/g, localize_common_format_value.replace('%1$s', localize_couse_longest_straight).replace('%2$s', course_data_list[index].straight));
        html = html.replace(/<-COURSE_ELEVATION->/g, localize_common_format_value.replace('%1$s', localize_couse_height_diff).replace('%2$s', course_data_list[index].elevation));
        html = html.replace(/<-COURSE_CORNER->/g, localize_common_format_value.replace('%1$s', localize_couse_corner_num).replace('%2$s', course_data_list[index].corner));

        this.contents_body = html;
        return html;
    },

    gt5CourseEdit: function (index) {
        if (service_write_photo != 0) {
            alert(localize_gtcom_cannot_write);
        }
        else {
            $('gt5_course_popup_comment').innerHTML = '\
			<dd><textarea name="course_comment" id="course_comment" class="course_comment_edit">' + course_data_list[index].comment + '</textarea></dd>\
			<dd class="popup_text_counter"><p id="popup_text_counter_course"></p></dd>\
			<dd id="popup_course_edit_button" class="popup_button">\
				<a href="javascript:void(0);" onclick="popup.gt5CourseEditCancel(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_cancel.png" alt="' + localize_common_cancel + '" /></a>\
				<a href="javascript:void(0);" onclick="gt5course.editComment(\'' + course_data_list[index].course_id + '\')"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_ok.png" alt="' + localize_common_ok + '" /></a>\
			</dd>\
			<dd class="popup_button"><img id="popup_button_off_cancel" src="/local/' + this.locale_url + '/images/gt5/buttons/sq_off.png" /><img id="popup_button_off_ok" src="/local/' + this.locale_url + '/images/gt5/buttons/sq_off.png" /></dd>\
			';
            var text_counter = new CousePopupTextCounter("course_comment", "popup_text_counter_course", "popup_button_off_ok", 140);
            Event.observe('course_comment', 'keyup', text_counter.execute.bind(text_counter));
        }
    },

    gt5CourseEditCancel: function (index) {
        $('gt5_course_popup_comment').innerHTML = '\
		<dd><pre>' + course_data_list[index].comment + '</pre></dd>\
		<dd id="popup_course_edit_button" class="popup_button">\
			<a href="javascript:void(0);" onclick="popup.gt5CourseEdit(' + index + ');"><img src="/local/' + this.locale_url + '/images/gt5/buttons/sq_comment.png" alt="' + localize_couse_comment_edit + '" /></a>\
		</dd>\
		';
    },

    getProfileDetail: function (data) {
        this.contents_title = '<h3>' + localize_profile_basic_infomation + '</h3>';
        var html = '\
	<dl class="popup_userprofile_avatar">\
		<dd class="avatar_bg color_' + data.menu_color + '">&nbsp;</dd>\
		<dd class="avatar"><-AVATAR-></dd>\
	</dl>\
	<dl class="popup_userprofile_data">\
		<dd class="online_id profile_popup"><p><span class="flag <-COUNTRY->">&nbsp;</span><-USER_ID-></p></dd>\
		<dd class="friend_count">' + localize_profile_friend_count + '&nbsp;<-FRIEND_COUNT-></dd>\
	</dl>\
	<dl class="popup_userprofile_level">\
		<dd class="level">' + localize_profile_aspec + ' <span class="level_text">' + localize_profile_lv + '</span> <span class="level_value"><-ASPEC_LEVEL-></span></dd>\
		<dd class="level">' + localize_profile_bspec + ' <span class="level_text">' + localize_profile_lv + '</span> <span class="level_value"><-BSPEC_LEVEL-></span></dd>\
		<dd class="license"><span>' + localize_profile_license + '</span><img src="<-LICENSE_IMAGE->" width="30" height="23" alt="license" /></dd>\
	</dl>\
	<dl class="popup_userprofile_comment">\
		<dt>' + localize_profile_comment + '</dt>\
		<dd><pre><-COMMENT-></pre></dd>\
	</dl>\
	<dl class="popup_userprofile_playtime">\
		<dt>' + localize_profile_play_time_s + '</dt>\
		<dd><-PLAYTIME-></dd>\
	</dl>\
';

        var friend_check = 0;
        for (i = 0; i < friend_data_list.length; i++) {
            if (friend_data_list[i].id == data.id) {
                friend_check = 1;
                break;
            }
        }

        this.contents_buttons = '\
	<dl class="popup_buttons">\
		<dd><a href="javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/close.png" height="20" alt="' + localize_common_close + '" /></a></dd>\
		';

        if (data.profile_level == 0 && data.id != online_id)
            this.contents_buttons += '<dd><a href="Javascript:void(0);" onclick="popup.openDirectMessage(\'<-USER_ID->\')"><img src="/local/' + this.locale_url + '/images/gt5/buttons/mail.png" height="20" alt="' + localize_common_write_mail + '" /></a></dd>';

        if (friend_check != 0)
            this.contents_buttons += '<dd><a href="/' + this.locale_url + '/gt5/user/<-USER_ID->/"><img src="/local/' + this.locale_url + '/images/gt5/buttons/home.png" height="20" alt="' + localize_profile_buton_user_home + '" /></a></dd>';
        this.contents_buttons += '\
	</dl>\
		';

        this.contents_buttons = this.contents_buttons.replace(/<-USER_ID->/g, data.id);

        if (data.photo_avatar != "")
            html = html.replace(/<-AVATAR->/g, '<img src="' + photo_base_url + data.photo_avatar + '_0.jpg" width="48" height="48" />');
        else
            html = html.replace(/<-AVATAR->/g, '');

        if (data.license_level == 0)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_b.png');
        else if (data.license_level == 1)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_a.png');
        else if (data.license_level == 2)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_ic.png');
        else if (data.license_level == 3)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_ib.png');
        else if (data.license_level == 4)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_ia.png');
        else if (data.license_level == 5)
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_s.png');
        else
            html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/user/license_base.png');

        html = html.replace(/<-USER_ID->/g, data.id);
        html = html.replace(/<-FRIEND_COUNT->/g, data.friend_count);
        html = html.replace(/<-COUNTRY->/g, data.country);
        html = html.replace(/<-ASPEC_LEVEL->/g, data.aspec_level);
        html = html.replace(/<-BSPEC_LEVEL->/g, data.bspec_level);
        html = html.replace(/<-BBS_ID->/g, data.number);
        html = html.replace(/<-COMMENT->/g, data.comment.replace(/\$/g, '&#36;'));
        html = html.replace(/<-PLAYTIME->/g, data.playtime.replace(/\$/g, '&#36;'));

        this.contents_body = html;
    },

    getDirectMessageHtml: function (online_id, select_switch) {
        var selected = "";
        this.contents_title = '<h3>' + localize_mode_mail + '</h3>';
        var html = '\
	<dl class="popup_mail_to">\
		<dt>' + localize_mail_to + '</dt>\
		';

        if (select_switch == true) {
            html += '\
		<dd><select name="online_id" id="send_message_to">\
			';
            for (i = 0; i < friend_data_list.length; i++) {
                if (target_profile.id != friend_data_list[i].id) {
                    selected = "";
                    if (online_id == friend_data_list[i].id) { selected = " selected"; }
                    html += '<option value="' + friend_data_list[i].id + '"' + selected + '>' + friend_data_list[i].id + '</option>';
                }
            }
            html += '</select></dd>';
        }
        else {
            html += '<dd>' + online_id + '</dd><input type="hidden" name="online_id" id="send_message_to" value="' + online_id + '" />';
        }
        html += '<dd id="gt5_popup_mail_avator" style="position:absolute;top:20px;right:20px;">&nbsp;</dd>';
        html += '</dl>';

        html += '\
	<dl class="popup_mail_main" id="popup_mail_mail">\
		<dt>' + localize_mail_subject + "&nbsp;" + localize_profile_within_n_letters.replace("%1$s", "40") + '<div class="popup_mailsend_counter"><p id="popup_mailsend_counter_subject"></p></div></dt>\
		<dd><input type="text" name="message_subject" id="send_message_subject" /></dd>\
		<dt>' + localize_mail_body + "&nbsp;" + localize_profile_within_n_letters.replace("%1$s", "250") + '<div class="popup_mailsend_counter"><p id="popup_mailsend_counter_body"></p></div></dt>\
		<dd><textarea name="message_body" id="send_message_body"></textarea></dd>\
	</dl>\
		';
        this.contents_buttons = '\
	<dl class="popup_buttons">\
		<dd><a href="Javascript:void(0);" onclick="gt5mail.sendMessage()"><img src="/local/' + this.locale_url + '/images/gt5/buttons/submit.png" height="20" alt="' + localize_mail_send + '" /></a><img id="submit_mail_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
		<dd><a href="Javascript:void(0);" onclick="popup.closePopup();"><img src="/local/' + this.locale_url + '/images/gt5/buttons/cancel.png" height="20" alt="' + localize_mail_cancel + '" /></a><img id="cancel_mail_button" class="button_canceler" src="/local/' + this.locale_url + '/images/gt5/buttons/off.png" height="20" alt="" /></dd>\
	<dl>\
		';
        this.contents_body = html;
    },
    getFriendListHtml: function () {
        var html = '<h3>é€ä¿¡ã™ã‚‹ç›¸æ‰‹ã‚’é¸ã¶</h3>';
        for (i = 0; i < friend_data_list.length; i++) {
            html += '\
		<dl>\
			<dd><a href="javascript:void(0)" onclick="popup.openDirectMessage(\'<-USER_ID->\')"><img src="/common/images/gt5/sample_friendlist_thumb.jpg" /></a></dd>\
			<dd><a href="javascript:void(0)" onclick="popup.openDirectMessage(\'<-USER_ID->\')"><-USER_ID-></a></dd>\
		</dl>\
			';
            html = html.replace(/<-USER_ID->/g, friend_data_list[i].id);
        }
        return html;
    }

});


/*----------------------*/
/* Ajaxé–¢é€£ã˜ã‚ƒãªã„ã‚‚ã® */
/*----------------------*/
var getDateDiffString = function (target_date, local) {
    var now_date = new Date();
    var post_date = Date.parseExact(target_date, 'yyyy-MM-ddTHH:mm:ssZ');
    var local_date = '';
    post_date.setTimezone("GMT");
    var diff = Math.floor((now_date - post_date) / 1000);
    var diff_string = '';
    var localized_month = '';
    var localized_date = '';

    if (diff < 60 * 2)
        diff_string = localize_common_diff_minute_1;
    else if (diff < 60 * 60)
        diff_string = localize_common_diff_minute_2.replace('%1$s', Math.floor(diff / 60));
    else if (diff < 60 * 60 * 2)
        diff_string = localize_common_diff_hour_1;
    else if (diff < 60 * 60 * 24)
        diff_string = localize_common_diff_hour_2.replace('%1$s', Math.floor(diff / 60 / 60));
    else {
        local_date = Date.parseExact(local, 'yyyy/MM/dd HH:mm:ss');
        localized_month = eval("localize_common_month_s_" + (local_date.getMonth() + 1));
        localized_date = eval("localize_common_day_" + local_date.getDate());
        diff_string = localize_common_diff_format_month_day.replace('%1$s', localized_month).replace('%2$s', localized_date) + "&nbsp;" + local_date.format("HH:MM");
    }

    return diff_string;
    //diff_string = post_date.toGMTString();
}

var countTest = function (e) {
    var bbsdata = $('bbs_input');
    var counter = $('bbs_characters_counter');
    counter.innerHTML = bbsdata.value.length + " / 140";
}

var formInputChecker = Class.create({
    qty: 0,
    button_id: "",
    text_counter: new Array(),
    input_ids: new Array(),
    max_length_flag: false,
    is_value_flag: false,

    initialize: function (target_input, button_id) {
        this.button_id = button_id;
        this.qty = target_input.length;
        for (i = 0; i < this.qty; i++) {
            this.input_ids[i] = target_input[i].input_id;
            this.text_counter[i] = new TextCounter(target_input[i].input_id, target_input[i].counter_id, this.button_id, target_input[i].max_length);
        }
    },

    execute: function () {
        this.max_length_flag = false;

        for (i = 0; i < this.qty; i++) {
            this.text_counter[i].execute();
            if (this.text_counter[i].lengthChecker())
                this.max_length_flag = true;
        }
        if (this.max_length_flag)
            $(this.button_id).style.display = "inline";
        else
            $(this.button_id).style.display = "none";
    }
});

var MailInputChecker = Class.create(formInputChecker,
{
    initialize: function ($super, target_input, button_id) {
        $super(target_input, button_id)
        $(this.button_id).style.display = "inline";
    },
    execute: function () {
        this.max_length_flag = false;
        this.is_value_flag = true;

        for (i = 0; i < this.qty; i++) {
            this.text_counter[i].execute();
            if (this.text_counter[i].lengthChecker())
                this.max_length_flag = true;
            if ($(this.input_ids[i]).value == "")
                this.is_value_flag = false;
        }

        if (this.max_length_flag || this.is_value_flag == false)
            $(this.button_id).style.display = "inline";
        else
            $(this.button_id).style.display = "none";
    }
});

var ProfileInputChecker = Class.create(formInputChecker,
{
    initialize: function (target_input, button_id) {
        this.button_id = button_id;
        this.qty = target_input.length;
        for (i = 0; i < this.qty; i++) {
            this.text_counter[i] = new ProfileEditTextCounter(target_input[i].input_id, target_input[i].counter_id, this.button_id, target_input[i].max_length);
        }
    }
});

var TextCounter = Class.create({
    max_length: 0,
    target_id: "",
    counter_id: "",
    button_id: "",

    initialize: function (target_id, counter_id, button_id, max_length) {
        this.target_id = target_id;
        this.counter_id = counter_id;
        this.button_id = button_id;
        this.max_length = max_length;
        this.text_update();
    },

    text_update: function () {
        if ($(this.target_id).value.length > this.max_length) {
            $(this.counter_id).style.color = "#c00";
            $(this.button_id).style.display = "inline";
        }
        else {
            $(this.counter_id).style.color = "#d0d0d0";
            $(this.button_id).style.display = "none";
        }
        $(this.counter_id).innerHTML = $(this.target_id).value.length + " / " + this.max_length;
    },

    lengthChecker: function () //æ–‡å­—æ•°ã‚ªãƒ¼ãƒã®å ´åˆã¯trueã‚’è¿”ã™
    {
        if ($(this.target_id).value.length > this.max_length)
            return true;
        else
            return false;
    },

    execute: function () {
        this.text_update();
    }
});

var CousePopupTextCounter = Class.create(TextCounter, {

});

var ProfileEditTextCounter = Class.create(TextCounter, {
    text_update: function () {
        if ($(this.target_id).value.length > this.max_length) {
            $(this.counter_id).style.color = "#c00";
            $(this.button_id).style.display = "inline";
        }
        else {
            $(this.counter_id).style.color = "#d0d0d0";
            $(this.button_id).style.display = "none";
        }
    }
});


var textCounter = function (target_input) {
    var max_length = 0;
    var target_data;
    var counter;
    if (target_input == "bbs_input")
        max_length = 140;
    target_data = $('bbs_input');
    counter = $('bbs_characters_counter');

    if (target_data.value.length > max_length || target_data.value.length == 0) {
        if (target_data.value.length > max_length)
            $('bbs_characters_counter').style.color = "#c00";
        $('bbs_submit_button').style.display = "block";
    }
    else {
        $('bbs_characters_counter').style.color = "#000";
        $('bbs_submit_button').style.display = "none";
    }

    counter.innerHTML = target_data.value.length + " / " + max_length;
}

var countCharacter = function (str) {
    var counter = $('bbs_characters_counter');
    counter.innerHTML = str.length + " / 140";
}

var textReEscape = function (str) {
    return str.replace(/\\'/g, "'");
}

var updateAnchor = function () {
    var friend_list_hash = '';
    var page_mode_hash = '#';

    if (url_hash[0])
        page_mode_hash = '#' + url_hash[0];
    if (url_hash[1])
        friend_list_hash = ',' + url_hash[1];

    $('gt5_mode_profile_anchor').href = '#profile' + friend_list_hash;
    $('gt5_mode_community_anchor').href = '#bbs' + friend_list_hash;
    $('gt5_modeselect_bbs_anchor').href = '#bbs' + friend_list_hash;
    $('gt5_modeselect_log_anchor').href = '#log' + friend_list_hash;
    $('gt5_modeselect_mail_anchor').href = '#mail' + friend_list_hash;

    if ($('gt5_modeselect_gift_anchor'))
        $('gt5_modeselect_gift_anchor').href = '#gift' + friend_list_hash;

    $('friendlist_psnid').href = page_mode_hash + ',psnid';
    $('friendlist_aspec').href = page_mode_hash + ',aspec';
    $('friendlist_bspec').href = page_mode_hash + ',bspec';

    if (friend_list_size == friend_data_list.compact().length) {
        if (url_hash[1] == "aspec")
            gt5friend_list.sortMyHomeFriendList("aspec");
        else if (url_hash[1] == "bspec")
            gt5friend_list.sortMyHomeFriendList("bspec");
        else
            gt5friend_list.sortMyHomeFriendList("psnid");
    }
}

var convertCondition = function (condition) {
    var condition_id = 2; // normal
    if (condition > 8) {
        condition_id = 1;
    }
    else if (condition < -8) {
        condition_id = 3;
    }
    return condition_id;
}

var laptimeFormat = function (laptime, format) {
    var minute = parseInt(laptime / 60000);
    var sec = parseInt(laptime % 60000 / 1000);
    var m_sec = laptime % 6000 % 1000;
    return format.replace(/%d/g, minute).replace(/%02d/g, ("0" + sec).slice(-2)).replace(/%03d/g, ("00" + m_sec).slice(-3));
}

var onlineCreditIconConverter = function (credit_text, locale_url) {
    var credit = credit_text.replace(/\D/g, "");
    var icon_id = 0;

    if (locale_url == 'jp')
        credit = parseInt(credit / 100);

    if (credit > 0 && credit < 50000)
        icon_id = 1;
    else if (credit >= 500 && credit < 200000)
        icon_id = 2;
    else if (credit >= 200000)
        icon_id = 3;

    return icon_id;
}

var nowLoading = function (flag) {
    if (flag == true) {
        var loding_tint = document.createElement('DIV');
        loding_tint.id = "loading_tintarea";
        document.body.appendChild(loding_tint);
        $('loading_tintarea').innerHTML = '<img style="margin-top:300px;" src="/common/images/gt5/loading_l.gif" width="24" height="24" alt="loading" />';
    }
    else {
        document.body.removeChild($('loading_tintarea'));
    }
}

var totalRaceTimer = function (base_total_time, base_user_time, format) {
    var now = new Date();
    //alert(base_time);
    //alert(laptimeFormat(now - base_time, format))
    var total_time = now - base_user_time + base_total_time - 19000;
    $('remote_info_total_time').innerHTML = laptimeFormat(total_time <= 0 ? 0 : total_time, format);
    //	$('remote_info_total_time').innerHTML = laptimeFormat(base_time, format);
}

/*------------------*/
/* ã‚¯ãƒªãƒƒã‚¯ã‚¤ãƒ™ãƒ³ãƒˆ */
/*------------------*/
var loadProfile = function () {
    url_hash[0] = "profile";
    updateAnchor();

    $('gt5mypage_contents').style.display = "none";
    $('community_menu').style.display = "none";

    var html = '\
	<div class="bg_wrapper" id="gt5_profile_view_wrapper">\
<div class="gt5_profile_spacer">&nbsp;</div>\
<table class="gt5_profile_table" border="0" cellpadding="0" cellspacing="0">\
	<tr class="aspec" title="' + localize_profile_exp + ' <-ASPEC_EXP-> / <-ASPEC_NEXTEXP->"><th><p>' + localize_profile_aspec_level + '</p></th><td><p><-ASPEC_LEVEL-></p></td></tr>\
	<tr class="bspec" title="' + localize_profile_exp + ' <-BSPEC_EXP-> / <-BSPEC_NEXTEXP->"><th><p>' + localize_profile_bspec_level + '</p></th><td><p><-BSPEC_LEVEL-></p></td></tr>\
	<tr><th><p>' + localize_profile_achievement + '</p></th><td><p><-ACHIEVEMENT-> %</p></td></tr>\
	<tr><th><p>' + localize_profile_credit + '</p></th><td><p><-CREDIT-></p></td></tr>\
	<tr><th><p>' + localize_profile_countofwin + '</p></th><td><p><-WIN_COUNT-></p></td></tr>\
	<tr><th><p>' + localize_profile_countofcar + '</p></th><td><p><-CAR_COUNT-></p></td></tr>\
	<tr><th><p>' + localize_profile_trophy + '</p></th><td><p><-TROPHY-> %</p></td></tr>\
	<tr><th><p>' + localize_profile_distance + '</p></th><td><p><-ODOMETER-></p></td></tr>\
</tr>\
</table>\
<dl class="gt5_profile_license">\
	<dd class="license"><span>' + localize_profile_license + '</span><img src="<-LICENSE_IMAGE->" /></dd>\
	<dd class="bar"><img src="/common/images/gt5/profile/license_bar.gif" /></dd>\
	<dd class="trophy"><img src="/common/images/gt5/profile/trophy_gold.png" /><span class="batten"> x </span><span class="trophy_value"><-LICENSE_GOLD-></span></dd>\
	<dd class="trophy"><img src="/common/images/gt5/profile/trophy_silver.png" /><span class="batten"> x </span><span class="trophy_value"><-LICENSE_SILVER-></span></dd>\
	<dd class="trophy"><img src="/common/images/gt5/profile/trophy_bronze.png" /><span class="batten"> x </span><span class="trophy_value"><-LICENSE_BRONZE-></span></dd>\
</dl>\
<p style="text-align:center; font-size:1px; margin-top:15px;"><img src="/common/images/gt5/main_hr.png" /><p>\
<div style="clear:both; height:1px; font-size:1px;">&nbsp;</div>\
<dl class="gt5_profile_driver_list" id="gt5_profile_driver_list">\
	<dt>' + localize_profile_driverlist + '</dt>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
</dl>\
<div style="clear:both; height:1px; font-size:1px;">&nbsp;</div>\
<dl class="gt5_profile_garage_list" id="gt5_profile_garage_list">\
	<dt>' + localize_profile_garage + '</dt>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
	<dd>&nbsp;</dd>\
</dl>\
</div>\
';

    //	<tr><th>License Level</th><td><-LICENSE_LEVEL-></td></tr>\
    html = html.replace(/<-ASPEC_EXP->/g, target_profile.aspec_exp);
    html = html.replace(/<-BSPEC_EXP->/g, target_profile.bspec_exp);
    html = html.replace(/<-ASPEC_NEXTEXP->/g, target_profile.aspec_expnextlevel);
    html = html.replace(/<-BSPEC_NEXTEXP->/g, target_profile.bspec_expnextlevel);

    html = html.replace(/<-ASPEC_LEVEL->/g, target_profile.aspec_level);
    html = html.replace(/<-BSPEC_LEVEL->/g, target_profile.bspec_level);
    html = html.replace(/<-ACHIEVEMENT->/g, target_profile.achievement);
    html = html.replace(/<-CREDIT->/g, target_profile.credit);
    //	html = html.replace(/<-CREDIT->/g, target_profile.credit.toString().split("").reverse().eachSlice(3,function(a){ return a.reverse().join("") }).reverse().join(","));
    html = html.replace(/<-WIN_COUNT->/g, target_profile.win_count);
    html = html.replace(/<-CAR_COUNT->/g, target_profile.car_count);
    html = html.replace(/<-TROPHY->/g, target_profile.trophy);
    html = html.replace(/<-ODOMETER->/g, target_profile.odometer);

    html = html.replace(/<-LICENSE_BRONZE->/g, target_profile.license_bronze);
    html = html.replace(/<-LICENSE_SILVER->/g, target_profile.license_silver);
    html = html.replace(/<-LICENSE_GOLD->/g, target_profile.license_gold);

    if (target_profile.license_level == 0)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_b.png');
    else if (target_profile.license_level == 1)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_a.png');
    else if (target_profile.license_level == 2)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_ic.png');
    else if (target_profile.license_level == 3)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_ib.png');
    else if (target_profile.license_level == 4)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_ia.png');
    else if (target_profile.license_level == 5)
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_s.png');
    else
        html = html.replace(/<-LICENSE_IMAGE->/g, '/common/images/gt5/profile/license_base.png');

    html = html.replace(/<-LICENSE_LEVEL->/g, target_profile.license_level);
    html = html.replace(/<-PROFILE_LEVEL->/g, target_profile.profile_level);

    //	var profile_driver = new GT5Bspec(locale_url);
    var profile_driver = new GT5Profile(target_profile.id, locale_url);
    profile_driver.getDriverListForProfileTab();

    //	var profile_garage = new GT5Bspec(locale_url);
    var profile_garage = new GT5Profile(target_profile.id, locale_url);
    profile_garage.getCarListForProfileTab();

    $('profile_view').innerHTML = html;

    if (online_id == target_profile.id)
        $('gt5_profile_view_wrapper').style.height = 905 + "px";
    else {
        $('profile_view').style.height = 1047 + "px";
    }
    $('profile_view').style.display = "block";
    $('gt5_mode_profile').className = "profile selected";
    $('gt5_mode_community').className = "community";

}
var loadCommunity = function () {
    url_hash[0] = "bbs";
    updateAnchor();

    $('profile_view').innerHTML = "";
    $('profile_view').style.display = "none";
    $('gt5mypage_contents').style.display = "block";
    $('community_menu').style.display = "block";
    $('gt5_mode_community').className = "community selected";
    $('gt5_mode_profile').className = "profile";
}

var loadBbs = function (locale_url) {
    url_hash[0] = "bbs";
    updateAnchor();

    gt5contents = new GT5Bbs(locale_url);
    gt5contents.getBbsCache();
    $('gt5_modeselect_bbs').className = "bbs on";
    $('gt5_modeselect_log').className = "log";
    if ($('gt5_modeselect_mail'))
        $('gt5_modeselect_mail').className = "mail";
    if ($('gt5_modeselect_gift'))
        $('gt5_modeselect_gift').className = "gift";
}
var loadLog = function (locale_url) {
    url_hash[0] = "log";
    updateAnchor();

    gt5contents = new GT5Log(locale_url);
    gt5contents.getFirstLog();
    $('gt5_modeselect_bbs').className = "bbs";
    $('gt5_modeselect_log').className = "log on";
    if ($('gt5_modeselect_mail'))
        $('gt5_modeselect_mail').className = "mail";
    if ($('gt5_modeselect_gift'))
        $('gt5_modeselect_gift').className = "gift";
}
var loadMail = function (locale_url) {
    url_hash[0] = "mail";
    updateAnchor();
    gt5contents = new GT5Mail(locale_url);
    gt5contents.getFirstLog();
    $('gt5_modeselect_bbs').className = "bbs";
    $('gt5_modeselect_log').className = "log";
    $('gt5_modeselect_mail').className = "mail on";
    if ($('gt5_modeselect_gift'))
        $('gt5_modeselect_gift').className = "gift";
}

var loadMailDirect = function () {
    popup.openDirectMessage(target_profile.id);
}

var loadGift = function (locale_url) {
    url_hash[0] = "gift";
    updateAnchor();
    gt5contents = new GT5Gift(locale_url);
    gt5contents.getFirstLog();
    $('gt5_modeselect_bbs').className = "bbs";
    $('gt5_modeselect_log').className = "log";
    if ($('gt5_modeselect_mail'))
        $('gt5_modeselect_mail').className = "mail";
    $('gt5_modeselect_gift').className = "gift on";
}

var loadFriendListPsnId = function () {
    $('friendlist_psnid').className = "on";
    $('friendlist_aspec').className = "off";
    $('friendlist_bspec').className = "off";
    url_hash[1] = "";
    updateAnchor();
}
var loadFriendListAspec = function () {
    $('friendlist_psnid').className = "off";
    $('friendlist_aspec').className = "on";
    $('friendlist_bspec').className = "off";
    url_hash[1] = "aspec";
    updateAnchor();
}
var loadFriendListBspec = function () {
    $('friendlist_psnid').className = "off";
    $('friendlist_aspec').className = "off";
    $('friendlist_bspec').className = "on";
    url_hash[1] = "bspec";
    updateAnchor();
}
var sortRemoteFriendListPsnId = function () {
    $('remote_friendlist_psnid').className = "on";
    $('remote_friendlist_aspec').className = "off";
    $('remote_friendlist_bspec').className = "off";
    gt5friend_list.sortFriendList("psn_id");
    gt5friend_list.getFriendListForBspec();
}
var sortRemoteFriendListAspec = function () {
    $('remote_friendlist_psnid').className = "off";
    $('remote_friendlist_aspec').className = "on";
    $('remote_friendlist_bspec').className = "off";
    gt5friend_list.sortFriendList("aspec");
    gt5friend_list.getFriendListForBspec();
}
var sortRemoteFriendListBspec = function () {
    $('remote_friendlist_psnid').className = "off";
    $('remote_friendlist_aspec').className = "off";
    $('remote_friendlist_bspec').className = "on";
    gt5friend_list.sortFriendList("bspec");
    gt5friend_list.getFriendListForBspec();
}

var loadRemoteRace = function (locale_url) {
    gt5bspec = new GT5Bspec(locale_url);
    //	if(online_id != target_profile.id)
    //		gt5bspec.openBspecWindowResult();
    //	else
    gt5bspec.openBspecWindow();
}
var loadRemoteRaceResult = function (locale_url) {
    gt5bspec = new GT5Bspec(locale_url);
    gt5bspec.openBspecWindowResult();
}
